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:
XmlPullParser event mapping 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 Classes Modifier and Type Interface Description static class
XmlPullParser.Event
static class
XmlPullParser.TagEvent
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
getAttributeCount()
java.lang.String
getAttributeName(int index)
Returns the loacalpart of the attribute's name ornull
in case the index does not refer to an attribute.java.lang.String
getAttributeNamespace(int index)
java.lang.String
getAttributePrefix(int index)
javax.xml.namespace.QName
getAttributeQName(int index)
java.lang.String
getAttributeType(int index)
java.lang.String
getAttributeValue(int index)
default java.lang.String
getAttributeValue(java.lang.String name)
java.lang.String
getAttributeValue(java.lang.String namespace, java.lang.String name)
int
getColumnNumber()
default java.lang.String
getDefaultNamespace()
int
getDepth()
XmlPullParser.Event
getEventType()
java.lang.String
getInputEncoding()
int
getLineNumber()
java.lang.String
getName()
Return the name for the current START_ELEMENT or END_ELEMENT event.java.lang.String
getNamespace()
java.lang.String
getNamespace(java.lang.String prefix)
int
getNamespaceCount()
java.lang.String
getNamespacePrefix(int pos)
java.lang.String
getNamespaceUri(int pos)
java.lang.String
getPositionDescription()
java.lang.String
getPrefix()
java.lang.Object
getProperty(java.lang.String name)
javax.xml.namespace.QName
getQName()
java.lang.String
getText()
boolean
isWhiteSpace()
XmlPullParser.Event
next()
XmlPullParser.TagEvent
nextTag()
java.lang.String
nextText()
Reads the content of a text-only element, an exception is thrown if this is not a text-only element.boolean
supportsRoundtrip()
-
-
-
Method Detail
-
getProperty
java.lang.Object getProperty(java.lang.String name)
-
getInputEncoding
java.lang.String getInputEncoding()
-
getNamespaceCount
int getNamespaceCount() throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespacePrefix
java.lang.String getNamespacePrefix(int pos) throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespaceUri
java.lang.String getNamespaceUri(int pos) throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespace
java.lang.String getNamespace(java.lang.String prefix)
-
getDefaultNamespace
default java.lang.String getDefaultNamespace()
-
getDepth
int getDepth()
-
getPositionDescription
java.lang.String getPositionDescription()
-
getLineNumber
int getLineNumber()
-
getColumnNumber
int getColumnNumber()
-
isWhiteSpace
boolean isWhiteSpace() throws XmlPullParserException
- Throws:
XmlPullParserException
-
getText
java.lang.String getText()
-
getNamespace
java.lang.String getNamespace()
-
getName
java.lang.String 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
javax.xml.namespace.QName getQName()
-
getPrefix
java.lang.String getPrefix()
-
getAttributeCount
int getAttributeCount()
-
getAttributeNamespace
java.lang.String getAttributeNamespace(int index)
-
getAttributeName
java.lang.String getAttributeName(int index)
Returns the loacalpart 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
javax.xml.namespace.QName getAttributeQName(int index)
-
getAttributePrefix
java.lang.String getAttributePrefix(int index)
-
getAttributeType
java.lang.String getAttributeType(int index)
-
getAttributeValue
java.lang.String getAttributeValue(int index)
-
getAttributeValue
java.lang.String getAttributeValue(java.lang.String namespace, java.lang.String name)
-
getAttributeValue
default java.lang.String getAttributeValue(java.lang.String name)
-
getEventType
XmlPullParser.Event getEventType() throws XmlPullParserException
- Throws:
XmlPullParserException
-
next
XmlPullParser.Event next() throws java.io.IOException, XmlPullParserException
- Throws:
java.io.IOException
XmlPullParserException
-
nextText
java.lang.String nextText() throws java.io.IOException, XmlPullParserException
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:
java.io.IOException
- in case of an IO error.XmlPullParserException
- in case of an XML pull parser error.
-
nextTag
XmlPullParser.TagEvent nextTag() throws java.io.IOException, XmlPullParserException
- Throws:
java.io.IOException
XmlPullParserException
-
supportsRoundtrip
boolean supportsRoundtrip()
-
-