|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
com.google.gdata.wireformats.XmlParser
public class XmlParser
XML parser, branched from XmlParser.
The plan is to integrate it tighter with the WireFormatParser
interface, remove unnecessary interfaces and parameters (in our new
data model, there is only one XmlParser.ElementHandler),
and move it away from the util package.
Existing data classes continue to use the old XML parser until they've been migrated to the new data model, at which point they will start to use the new 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(Element) method.
XmlParser.ElementHandler| Field Summary | |
|---|---|
protected java.util.Map<java.lang.String,java.util.Stack<com.google.gdata.wireformats.XmlParser.NamespaceDecl>> |
namespaceMap
Set of all namespace declarations valid at the current location. |
protected StreamProperties |
props
Input properties for parsing |
protected java.lang.String |
rootElementName
Root element name. |
protected com.google.gdata.wireformats.XmlParser.ElementHandler |
rootHandler
Root element handler. |
protected java.lang.String |
rootNamespace
Root element namespace URI. |
| Constructor Summary | |
|---|---|
XmlParser(StreamProperties props,
java.io.Reader r,
java.nio.charset.Charset cs)
Construct XML parser for given reader. |
|
XmlParser(StreamProperties props,
XmlEventSource eventSource)
Construct XML parser for a given event source. |
|
| Method Summary | |
|---|---|
void |
characters(char[] text,
int start,
int len)
SAX callback. |
protected XmlHandler |
createRootHandler(ValidationContext vc,
Element element,
ElementMetadata<?,?> metadata)
Create the xml handler for the root element. |
void |
endElement(java.lang.String namespace,
java.lang.String localName,
java.lang.String qName)
SAX callback. |
void |
endPrefixMapping(java.lang.String alias)
SAX callback. |
void |
ignorableWhitespace(char[] text,
int start,
int len)
SAX callback. |
Element |
parse(Element element)
Parse content from a source provided to the parser at construction time. |
void |
setDocumentLocator(org.xml.sax.Locator newLocator)
SAX callback. |
void |
startElement(java.lang.String namespace,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
SAX callback. |
void |
startPrefixMapping(java.lang.String alias,
java.lang.String uri)
SAX callback. |
protected void |
throwParseException(ParseException e)
Throws a parse exception with line/column information. |
| Methods inherited from class org.xml.sax.helpers.DefaultHandler |
|---|
endDocument, error, fatalError, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final StreamProperties props
protected com.google.gdata.wireformats.XmlParser.ElementHandler rootHandler
protected java.lang.String rootNamespace
protected java.lang.String rootElementName
protected java.util.Map<java.lang.String,java.util.Stack<com.google.gdata.wireformats.XmlParser.NamespaceDecl>> namespaceMap
| Constructor Detail |
|---|
public XmlParser(StreamProperties props,
java.io.Reader r,
java.nio.charset.Charset cs)
props - stream properties for parsingr - reader where input is retrieved fromcs - character set used to encode input
public XmlParser(StreamProperties props,
XmlEventSource eventSource)
props - stream properties for parsingeventSource - event source| Method Detail |
|---|
public Element parse(Element element)
throws java.io.IOException,
ParseException,
ContentValidationException
WireFormatParser
parse in interface WireFormatParserelement - root of parsed element tree
java.io.IOException - if content cannot be accessed
ParseException - if content cannot be parsed invalid
ContentValidationException - if content fails metadata validation
protected XmlHandler createRootHandler(ValidationContext vc,
Element element,
ElementMetadata<?,?> metadata)
protected void throwParseException(ParseException e)
throws ParseException
ParseException
public void startElement(java.lang.String namespace,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void endElement(java.lang.String namespace,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void characters(char[] text,
int start,
int len)
throws org.xml.sax.SAXException
characters in interface org.xml.sax.ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void ignorableWhitespace(char[] text,
int start,
int len)
throws org.xml.sax.SAXException
ignorableWhitespace in interface org.xml.sax.ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXExceptionpublic void setDocumentLocator(org.xml.sax.Locator newLocator)
setDocumentLocator in interface org.xml.sax.ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandler
public void startPrefixMapping(java.lang.String alias,
java.lang.String uri)
startPrefixMapping in interface org.xml.sax.ContentHandlerstartPrefixMapping in class org.xml.sax.helpers.DefaultHandlerpublic void endPrefixMapping(java.lang.String alias)
endPrefixMapping in interface org.xml.sax.ContentHandlerendPrefixMapping in class org.xml.sax.helpers.DefaultHandler
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||