public class

XmlParser

extends DefaultHandler
java.lang.Object
   ↳ org.xml.sax.helpers.DefaultHandler
     ↳ com.google.gdata.util.XmlParser
Known Direct Subclasses

Class Overview

XML parser.

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.

Summary

Nested Classes
class XmlParser.ElementHandler Base class for custom element handlers. 
Fields
XmlParser.ElementHandler curHandler Top of the element handler stack.
ArrayList<XmlNamespace> elementNamespaces Namespace declarations for the current element.
Locator locator Document locator used to get line and column numbers for SAX events.
private static final Logger logger
protected HashMap<String, Stack<XmlParser.NamespaceDecl>> namespaceMap Set of all namespace declarations valid at the current location.
private static SAXParserFactory parserFactory
protected String rootElementName Root element name.
protected XmlParser.ElementHandler rootHandler Root element handler.
protected String rootNamespace Root element namespace URI.
int unrecognizedElements Number of unrecognized elements on the stack.
Public Constructors
XmlParser()
Public Methods
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.
void parse(InputStream input, 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 parse(Reader reader, XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName)
Parses XML.
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 Methods
void parse(InputSource is)
Parses XML.
void throwParseException(ParseException e)
Throws a parse exception with line/column information.
[Expand]
Inherited Methods
From class org.xml.sax.helpers.DefaultHandler
From class java.lang.Object
From interface org.xml.sax.ContentHandler
From interface org.xml.sax.DTDHandler
From interface org.xml.sax.EntityResolver
From interface org.xml.sax.ErrorHandler

Fields

XmlParser.ElementHandler curHandler

Top of the element handler stack.

ArrayList<XmlNamespace> elementNamespaces

Namespace declarations for the current element. Valid during startElement(String, String, String, Attributes).

Locator locator

Document locator used to get line and column numbers for SAX events.

private static final Logger logger

protected HashMap<String, Stack<XmlParser.NamespaceDecl>> namespaceMap

Set of all namespace declarations valid at the current location. Includes namespace declarations from all ancestor elements.

private static SAXParserFactory parserFactory

protected String rootElementName

Root element name.

protected XmlParser.ElementHandler rootHandler

Root element handler.

protected String rootNamespace

Root element namespace URI.

int unrecognizedElements

Number of unrecognized elements on the stack.

Public Constructors

public XmlParser ()

Public Methods

public void characters (char[] text, int start, int len)

SAX callback.

Parameters
text
start
len
Throws
SAXException

public void endElement (String namespace, String localName, String qName)

SAX callback.

Parameters
namespace
localName
qName
Throws
SAXException

public void endPrefixMapping (String alias)

SAX callback.

Parameters
alias

public void ignorableWhitespace (char[] text, int start, int len)

SAX callback.

Parameters
text
start
len
Throws
SAXException

public void parse (InputStream input, XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName)

Parses XML.

Parameters
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.
Throws
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)

Parses XML from a content source provided to the parser at construction time.

Parameters
rootHandler The root element handler corresponding to the expected document type.
rootNamespace Root element namespace URI.
rootElementName Root element name.
Throws
IOException Thrown by reader.
ParseException XML failed to validate against the schema implemented by rootHandler.

public void parse (Reader reader, XmlParser.ElementHandler rootHandler, String rootNamespace, String rootElementName)

Parses XML.

Parameters
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.
Throws
IOException Thrown by reader.
ParseException XML failed to validate against the schema implemented by rootHandler.

public void setDocumentLocator (Locator locator)

SAX callback.

Parameters
locator

public void startElement (String namespace, String localName, String qName, Attributes attrs)

SAX callback.

Parameters
namespace
localName
qName
attrs
Throws
SAXException

public void startPrefixMapping (String alias, String uri)

SAX callback.

Parameters
alias
uri

Protected Methods

protected void parse (InputSource is)

Parses XML.

Parameters
is Supplies the XML to parse.
Throws
IOException Thrown by is.
ParseException XML failed to validate against the schema implemented by rootHandler.

protected void throwParseException (ParseException e)

Throws a parse exception with line/column information.

Parameters
e