Package org.jivesoftware.smack.xml
Interface XmlPullParser
- All Known Implementing Classes:
StaxXmlPullParser
,Xpp3XmlPullParser
public interface XmlPullParser
Smack's interface for XML pull parsers. The main XML parser implementations are "Xml Pull Parser 3" (XPP3) on Android and "Streaming API for XML" (StAX, JSR 173) on Java.
Differences from StAX's XMLStreamReader are:
getName()
andgetAttributeName(int)
return localname, there isgetQName()
andgetAttributeQName(int)
to retrieve the qualified name (QName
).nextText()
instead ofXMLStreamReader.getElementText()
.
Differences from XPP3's XmlPullParser are:
- Methods taking an attribute, like
getAttributeName(int)
index returnnull
instead of throwing an exception if no attribute with the given index exists.
Developer Information
The following table shows the mapping of Smack's XmlPullParser events to StAX and XPP3 events:
Smack's XmlPullParser.Event | StAX Event | XPP3 Event |
---|---|---|
XmlPullParser.Event.START_DOCUMENT | START_DOCUMENT (7) | START_DOCUMENT (0) |
XmlPullParser.Event.END_DOCUMENT | END_DOCUMENT (8) | END_DOCUMENT (1) |
XmlPullParser.Event.START_ELEMENT | START_ELEMENT (1) | START_TAG (2) |
XmlPullParser.Event.END_ELEMENT | END_ELEMENT (2) | END_TAG (3) |
XmlPullParser.Event.TEXT_CHARACTERS | CHARACTERS (4) | TEXT (4) |
XmlPullParser.Event.PROCESSING_INSTRUCTION | PROCESSING_INSTRUCTION (3) | PROCESSING_INSTRUCTION (8) |
XmlPullParser.Event.COMMENT | COMMENT (5) | COMMENT (9) |
XmlPullParser.Event.IGNORABLE_WHITESPACE | SPACE (6) | IGNORABLE_WHITESPACE (7) |
XmlPullParser.Event.ENTITY_REFERENCE | ENTITY_REFERENCE (9) | ENTITY_REF (6) |
XmlPullParser.Event.OTHER | ENTITY_REFERENCE (9) | ENTITY_REF (6) |
XmlPullParser.Event.OTHER
includes
in case of StAX: ATTRIBUTE (10), DTD (11), CDATA (12), NAMESPACE (13), NOTATION_DECLARATION (14) and ENTITY_DECLRATION (15),
in case of XPP3: CDSECT (5), DOCDECL (10).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
static enum
-
Method Summary
Modifier and TypeMethodDescriptionint
getAttributeName
(int index) Returns the localpart of the attribute's name ornull
in case the index does not refer to an attribute.getAttributeNamespace
(int index) getAttributePrefix
(int index) getAttributeQName
(int index) getAttributeType
(int index) getAttributeValue
(int index) default String
getAttributeValue
(String name) getAttributeValue
(String namespace, String name) int
default String
int
getDepth()
int
getName()
Return the name for the current START_ELEMENT or END_ELEMENT event.getNamespace
(String prefix) int
getNamespacePrefix
(int pos) getNamespaceUri
(int pos) getProperty
(String name) getQName()
getText()
boolean
next()
nextTag()
nextText()
Reads the content of a text-only element, an exception is thrown if this is not a text-only element.boolean
-
Method Details
-
getProperty
-
getInputEncoding
-
getNamespaceCount
- Throws:
XmlPullParserException
-
getNamespacePrefix
- Throws:
XmlPullParserException
-
getNamespaceUri
- Throws:
XmlPullParserException
-
getNamespace
-
getDefaultNamespace
-
getDepth
int getDepth() -
getPositionDescription
-
getLineNumber
int getLineNumber() -
getColumnNumber
int getColumnNumber() -
isWhiteSpace
- Throws:
XmlPullParserException
-
getText
-
getNamespace
-
getName
Return the name for the current START_ELEMENT or END_ELEMENT event. This method must only be called if the current event is START_ELEMENT or END_ELEMENT.- Returns:
- the name for the current START_ELEMETN or END_ELEMENT event.
-
getQName
-
getPrefix
-
getAttributeCount
int getAttributeCount() -
getAttributeNamespace
-
getAttributeName
Returns the localpart of the attribute's name ornull
in case the index does not refer to an attribute.- Parameters:
index
- the attribute index.- Returns:
- the localpart of the attribute's name or
null
.
-
getAttributeQName
-
getAttributePrefix
-
getAttributeType
-
getAttributeValue
-
getAttributeValue
-
getAttributeValue
-
getEventType
- Throws:
XmlPullParserException
-
next
- Throws:
IOException
XmlPullParserException
-
nextText
Reads the content of a text-only element, an exception is thrown if this is not a text-only element.- Precondition: the current event is START_ELEMENT.
- Postcondition: the current event is the corresponding END_ELEMENT.
- Returns:
- the textual content of the current element.
- Throws:
IOException
- in case of an IO error.XmlPullParserException
- in case of an XML pull parser error.
-
nextTag
- Throws:
IOException
XmlPullParserException
-
supportsRoundtrip
boolean supportsRoundtrip()
-