public class XmlParser extends org.xml.sax.helpers.DefaultHandler
This is a thin layer on top of a SAX parser. The key concept necessary to understand this parser is Element Handler. Element handlers are type-specific parsers. Each handler instance contains an instance of the Java type corresponding to the XML type it parses. At any given time, one handler is active, and zero or more handlers are kept on the stack. This corresponds directly to the set of currently opened XML tags.
To use this parser, one must define an XmlParser.ElementHandler type (usually one per XML schema type),
specify the root element handler, and pass a reader to the
parse(Reader, com.google.gdata.util.XmlParser.ElementHandler, String,
String) method.
XmlParser.ElementHandler| Modifier and Type | Class and Description |
|---|---|
static class |
XmlParser.ElementHandler
Base class for custom element handlers.
|
| Modifier and Type | Field and Description |
|---|---|
protected HashMap<String,Stack<com.google.gdata.util.XmlParser.NamespaceDecl>> |
namespaceMap
Set of all namespace declarations valid at the current location.
|
protected String |
rootElementName
Root element name.
|
protected XmlParser.ElementHandler |
rootHandler
Root element handler.
|
protected String |
rootNamespace
Root element namespace URI.
|
| Constructor and Description |
|---|
XmlParser() |
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] text,
int start,
int len)
SAX callback.
|
void |
endElement(String namespace,
String localName,
String qName)
SAX callback.
|
void |
endPrefixMapping(String alias)
SAX callback.
|
void |
ignorableWhitespace(char[] text,
int start,
int len)
SAX callback.
|
protected void |
parse(InputSource is)
Parses XML.
|
void |
parse(InputStream input,
XmlParser.ElementHandler rootHandler,
String rootNamespace,
String rootElementName)
Parses XML.
|
void |
parse(Reader reader,
XmlParser.ElementHandler rootHandler,
String rootNamespace,
String rootElementName)
Parses XML.
|
void |
parse(XmlParser.ElementHandler rootHandler,
String rootNamespace,
String rootElementName)
Parses XML from a content source provided to the parser at
construction time.
|
void |
setDocumentLocator(Locator locator)
SAX callback.
|
void |
startElement(String namespace,
String localName,
String qName,
Attributes attrs)
SAX callback.
|
void |
startPrefixMapping(String alias,
String uri)
SAX callback.
|
protected void |
throwParseException(ParseException e)
Throws a parse exception with line/column information.
|
endDocument, error, fatalError, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, unparsedEntityDecl, warningprotected XmlParser.ElementHandler rootHandler
protected String rootNamespace
protected String rootElementName
public void parse(Reader reader, XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName) throws IOException, ParseException
reader - Supplies the XML to parse.rootHandler - The root element handler corresponding to the expected document
type.rootNamespace - Root element namespace URI.rootElementName - Root element name.IOException - Thrown by reader.ParseException - XML failed to validate against the schema implemented by
rootHandler.public void parse(InputStream input, XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName) throws IOException, ParseException
input - Supplies the XML to parse.rootHandler - The root element handler corresponding to the expected document
type.rootNamespace - Root element namespace URI.rootElementName - Root element name.IOException - Thrown by input.ParseException - XML failed to validate against the schema implemented by
rootHandler.public void parse(XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName) throws IOException, ParseException
rootHandler - The root element handler corresponding to the expected document
type.rootNamespace - Root element namespace URI.rootElementName - Root element name.IOException - Thrown by reader.ParseException - XML failed to validate against the schema implemented by
rootHandler.protected void parse(InputSource is) throws IOException, ParseException
is - Supplies the XML to parse.IOException - Thrown by is.ParseException - XML failed to validate against the schema implemented by
rootHandler.protected void throwParseException(ParseException e) throws ParseException
ParseExceptionpublic void startElement(String namespace, String localName, String qName, Attributes attrs) throws SAXException
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endElement(String namespace, String localName, String qName) throws SAXException
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void characters(char[] text,
int start,
int len)
throws SAXException
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void ignorableWhitespace(char[] text,
int start,
int len)
throws SAXException
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void setDocumentLocator(Locator locator)
setDocumentLocator in interface ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandlerpublic void startPrefixMapping(String alias, String uri)
startPrefixMapping in interface ContentHandlerstartPrefixMapping in class org.xml.sax.helpers.DefaultHandlerpublic void endPrefixMapping(String alias)
endPrefixMapping in interface ContentHandlerendPrefixMapping in class org.xml.sax.helpers.DefaultHandlerCopyright © 2012. All Rights Reserved.