|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.xolite.impl.BaseXMLEventParser net.sf.xolite.sax.SaxXMLEventParser
public class SaxXMLEventParser
A XMLEventParser
implementation based on a SAX parser.
Constructor Summary | |
---|---|
SaxXMLEventParser()
Build a StreamXMLEventParser using the system-default SAXParser configured to be namespace aware
and perform no validation. |
|
SaxXMLEventParser(String schemaLocations)
Build a StreamXMLEventParser using the system-default SAXParser configured to be namespace aware
and perform validation using the provided schema locations. |
|
SaxXMLEventParser(XMLReader rdr)
Build a SimpleSaxParser using the given XMLReader . |
Method Summary | |
---|---|
protected void |
addLocationInfo(XMLParseException xpe)
|
protected void |
endElementImpl(String uri,
String localName)
|
Iterator<String> |
getAttributeNameIterator(String attrNamespaceURI)
Get an iterator on names of all the attributes present in the current element and belonging to the given namespace. |
Iterator<String> |
getAttributeNamespaceIterator()
Get an iterator on namespaces of all the attributes present in the current element. |
String |
getAttributeValue(String attrName)
Get an attribute value. |
String |
getAttributeValueNS(String attrNamespaceURI,
String attrName)
Get value of an attribute with namespace. |
String |
getElementText()
Get the content of the text buffer. |
Locator |
getLocator()
Get the current SAX locator (for reporting SAXParseException). |
ContentHandler |
initForExternalRead(XMLSerializable rootHandler)
|
XMLSerializable |
parse(File f)
Parse the given file to java objects. |
void |
parse(File f,
XMLSerializable rootHandler)
Parse a file to java objects using the given XMLSerializable as root handler (as object representing the root
element). |
XMLSerializable |
parse(InputSource src)
Parse the given input source to java objects. |
void |
parse(InputSource src,
XMLSerializable rootHandler)
Parse an input source to java objects using the given XMLSerializable as root handler (as object representing
the root element). |
XMLSerializable |
parse(InputStream is)
Parse the given input stream to java objects. |
void |
parse(InputStream is,
XMLSerializable rootHandler)
Parse an input stream to java objects using the given XMLSerializable as root handler (as object representing
the root element). |
XMLSerializable |
parse(URL url)
Parse the given URL content to java objects. |
void |
parse(URL url,
XMLSerializable rootHandler)
Parse an URL content to java objects using the given XMLSerializable as root handler (as object representing the
root element). |
protected void |
pushPrefixMappingInNextLevel(String newPrefix,
String newNamespaceURI)
Rem: overridden just to increase visibility. |
protected void |
transformAndThrowException(Exception source)
|
Methods inherited from class net.sf.xolite.impl.BaseXMLEventParser |
---|
delegateParsingTo, getCurrentDefinedNamespaces, getCurrentElementName, getCustomObject, getFactory, getLastParsedObject, getNamespaceURI, getPrefix, getPrefixes, getQualifiedName, isFirstEvent, isLastEvent, parseElement, putCustomObject, setFactory, setup, startElementImpl, tearDown, throwParseException, throwUnexpectedElementException, throwUnexpectedNamespaceException |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SaxXMLEventParser()
StreamXMLEventParser
using the system-default SAXParser
configured to be namespace aware
and perform no validation.
SAXParserFactory
,
SAXParser
public SaxXMLEventParser(String schemaLocations)
StreamXMLEventParser
using the system-default SAXParser
configured to be namespace aware
and perform validation using the provided schema locations. The 'schemaLocations' string must be a suite of pair 'namespace
URI' + 'schema location URL' separated by spaces (just as the value of the standard 'xsi:schemaLocation' xml attribute).
Caution: This setup works with Sun JRE default parser (Xerces) but is not guaranteed to work if you (or a library
you're using) have changed the default XML parser implementation.
In this case, you have to setup a validating parser yourself (following your parser documentation) and pass it to the
SaxXMLEventParser(XMLReader)
constructor.
schemaLocations
- the schema location expressed as in the standard 'xsi:schemaLocation' xml attributes. You can use the X-O lite
SchemaLocation helper to build this string if your schema is in your application jar.SAXParserFactory
,
SAXParser
,
SchemaLocation
public SaxXMLEventParser(XMLReader rdr)
SimpleSaxParser
using the given XMLReader
. The XMLReader
must be correctly
configured, this class will not change it's configuration (namespace aware, validating, ...).
Method Detail |
---|
public ContentHandler initForExternalRead(XMLSerializable rootHandler)
public XMLSerializable parse(File f) throws XMLParseException
f
- file containing the XML to parse.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public void parse(File f, XMLSerializable rootHandler) throws XMLParseException
XMLSerializable
as root handler (as object representing the root
element).
f
- file containing the XML to parse.rootHandler
- the root handler.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public XMLSerializable parse(InputStream is) throws XMLParseException
is
- input stream containing the XML to parse.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public void parse(InputStream is, XMLSerializable rootHandler) throws XMLParseException
XMLSerializable
as root handler (as object representing
the root element).
is
- input stream containing the XML to parse.rootHandler
- the root handler.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public XMLSerializable parse(URL url) throws XMLParseException
url
- URL pointing to file containing the XML to parse.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public void parse(URL url, XMLSerializable rootHandler) throws XMLParseException
XMLSerializable
as root handler (as object representing the
root element).
url
- URL pointing to file containing the XML to parse.rootHandler
- the root handler.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public XMLSerializable parse(InputSource src) throws XMLParseException
src
- input source for the SAX parsing.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public void parse(InputSource src, XMLSerializable rootHandler) throws XMLParseException
XMLSerializable
as root handler (as object representing
the root element).
src
- input source for the SAX parsing.rootHandler
- the root handler.
XMLParseException
- if the source cannot be read or contains an invalid XML document.public Locator getLocator()
public String getElementText()
XMLEventParser
Use the ElementText helper class to get, parse, validate and format easily the element text.
Calling this method from a startElement
notification is useful only when parsing XML with mixed content. In this
case you got the text just before the started element.
protected void addLocationInfo(XMLParseException xpe)
addLocationInfo
in class BaseXMLEventParser
protected void transformAndThrowException(Exception source) throws XMLParseException
transformAndThrowException
in class BaseXMLEventParser
XMLParseException
public String getAttributeValue(String attrName) throws XMLParseException
XMLEventParser
attrName
- the name of the attribute.
XMLParseException
public String getAttributeValueNS(String attrNamespaceURI, String attrName) throws XMLParseException
XMLEventParser
This method allows to specify the namespace of the attribute. In most of the case attributes are not associated to namespaces. It is not necessary because attributes definitions are, in most of the case, local to the definition of the element containing it. So this method should be rarely used (use the corresponding method without namespace parameter). Examples of attributes using namespaces are: 'xml:lang' or 'xmlns:prefix'. To get values of those attributes you must provide the namespace URI.
attrNamespaceURI
- the namespace URI of the attribute.attrName
- the name of the attribute.
XMLParseException
public Iterator<String> getAttributeNamespaceIterator() throws XMLParseException
XMLEventParser
XMLParseException
public Iterator<String> getAttributeNameIterator(String attrNamespaceURI) throws XMLParseException
XMLEventParser
null
as namespace for attributes not bound to a namespace (i.e. most of the attributes).
attrNamespaceURI
- namespace of the attributes or null
for attributes without namespaces.
XMLParseException
protected void endElementImpl(String uri, String localName) throws Exception
endElementImpl
in class BaseXMLEventParser
Exception
protected void pushPrefixMappingInNextLevel(String newPrefix, String newNamespaceURI)
pushPrefixMappingInNextLevel
in class BaseXMLEventParser
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |