Interface XmlPullParser
public interface XmlPullParser
Generic interface for simple and quick XML Pull Parser.
- Author:
- Aleksander Slominski
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteelement content was just readstatic final bytesignal logical end of xml documentstatic final byteend tag was just readstatic final bytestart tag was just read -
Method Summary
Modifier and TypeMethodDescriptionintintReturn how big is content.intgetDepth()Returns the current depth of the element.byteReturns the type of the current element (START_TAG, END_TAG, CONTENT, etc)intReturns the local name of the current element (current event must be START_TAG or END_TAG)intgetNamespacesLength(int depth) Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)Returns the prefix of the current element or null if elemet has no prefix.getQNameLocal(String qName) Return local part of qname.getQNameUri(String qName) Return uri part of qname.Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)booleanIs mixed element context allowed?booleanIs parser going to report namespace attributes (xmlns*) ?booleanIs parser namespace aware?booleanCheck if last CONTENT contained only whitespace characters.bytenext()Get next parsing event.Read current content as Stirng.voidreadEndTag(XmlEndTag etag) Read current end tag.voidreadNamespacesPrefixes(int depth, String[] prefixes, int off, int len) Return namespace prefixes for element at depthvoidreadNamespacesUris(int depth, String[] uris, int off, int len) Return namespace URIs for element at depthbyteRead subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).voidRead node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.voidreadStartTag(XmlStartTag stag) Read current start tag.voidreset()Reset the parser state.voidsetAllowedMixedContent(boolean enable) Allow for mixed element content.voidsetInput(char[] buf) Set the input for parser.voidsetInput(char[] buf, int off, int len) Set the input for parser.voidSet the input for parser.voidsetNamespaceAttributesReporting(boolean enable) Make parser to report xmlns* attributes.voidsetNamespaceAware(boolean enable) Indicate that the parser understands XML NamespacesbyteskipNode()Goes directly to the next sibling
-
Field Details
-
END_DOCUMENT
static final byte END_DOCUMENTsignal logical end of xml document- See Also:
-
START_TAG
static final byte START_TAGstart tag was just read- See Also:
-
END_TAG
static final byte END_TAGend tag was just read- See Also:
-
CONTENT
static final byte CONTENTelement content was just read- See Also:
-
-
Method Details
-
setInput
Set the input for parser.- Throws:
XmlPullParserException
-
setInput
Set the input for parser.- Throws:
XmlPullParserException
-
setInput
Set the input for parser.- Throws:
XmlPullParserException
-
reset
-
isAllowedMixedContent
boolean isAllowedMixedContent()Is mixed element context allowed? -
setAllowedMixedContent
Allow for mixed element content. Disabled by default. When disbaled element must containt either text or other elements.NOTE: this is not resetable parameter.
- Throws:
XmlPullParserException
-
isNamespaceAware
boolean isNamespaceAware()Is parser namespace aware? -
setNamespaceAware
Indicate that the parser understands XML NamespacesNOTE: this is not resetable parameter.
- Throws:
XmlPullParserException
-
isNamespaceAttributesReporting
boolean isNamespaceAttributesReporting()Is parser going to report namespace attributes (xmlns*) ? -
setNamespaceAttributesReporting
Make parser to report xmlns* attributes. Disabled by default. Only meaningful when namespaces are enabled (when namespaces are disabled all attributes are always reported).- Throws:
XmlPullParserException
-
getNamespaceUri
String getNamespaceUri()Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG) -
getLocalName
String getLocalName()Returns the local name of the current element (current event must be START_TAG or END_TAG) -
getPrefix
String getPrefix()Returns the prefix of the current element or null if elemet has no prefix. (current event must be START_TAG or END_TAG) -
getRawName
String getRawName()Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG) -
getQNameLocal
Return local part of qname. For example for 'xsi:type' it returns 'type'.- Throws:
XmlPullParserException
-
getQNameUri
Return uri part of qname. It is depending on current state of parser to find what namespace uri is mapped from namespace prefix. For example for 'xsi:type' if xsi namespace prefix was declared to 'urn:foo' it will return 'urn:foo'.- Throws:
XmlPullParserException
-
getDepth
int getDepth()Returns the current depth of the element. -
getNamespacesLength
int getNamespacesLength(int depth) -
readNamespacesPrefixes
void readNamespacesPrefixes(int depth, String[] prefixes, int off, int len) throws XmlPullParserException Return namespace prefixes for element at depth- Throws:
XmlPullParserException
-
readNamespacesUris
Return namespace URIs for element at depth- Throws:
XmlPullParserException
-
getPosDesc
String getPosDesc() -
getLineNumber
int getLineNumber() -
getColumnNumber
int getColumnNumber() -
next
Get next parsing event.NOTE: empty element (such as <tag/>) will be reported with just two events: START_TAG, END_TAG - it must be so to preserve parsing equivalency of empty element to <tag></tag>.
- Throws:
XmlPullParserExceptionIOException
-
getEventType
Returns the type of the current element (START_TAG, END_TAG, CONTENT, etc)- Throws:
XmlPullParserException
-
isWhitespaceContent
Check if last CONTENT contained only whitespace characters.- Throws:
XmlPullParserException
-
getContentLength
Return how big is content.NOTE: parser must be on CONTENT event.
- Throws:
XmlPullParserException
-
readContent
Read current content as Stirng.NOTE: parser must be on CONTENT event.
- Throws:
XmlPullParserException
-
readEndTag
Read current end tag.NOTE: parser must be on END_TAG event.
- Throws:
XmlPullParserException
-
readStartTag
Read current start tag.NOTE: parser must be on START_TAG event.
- Throws:
XmlPullParserException
-
readNodeWithoutChildren
Read node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.NOTE: parser must be on START_TAG event. and all events will written into node!
- Throws:
XmlPullParserException
-
readNode
Read subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).NOTE: parser must be on START_TAG event. and all events will written into node!
- Throws:
XmlPullParserExceptionIOException
-
skipNode
Goes directly to the next siblingNOTE: parser must be on START_TAG event. and all intermittent events will be lost!
- Throws:
XmlPullParserExceptionIOException
-