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
-
-
-
Method Detail
-
getProperty
Object getProperty(String name)
-
getInputEncoding
String getInputEncoding()
-
getNamespaceCount
int getNamespaceCount() throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespacePrefix
String getNamespacePrefix(int pos) throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespaceUri
String getNamespaceUri(int pos) throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespace
String getNamespace(String prefix)
-
getDefaultNamespace
default String getDefaultNamespace()
-
getDepth
int getDepth()
-
getPositionDescription
String getPositionDescription()
-
getLineNumber
int getLineNumber()
-
getColumnNumber
int getColumnNumber()
-
isWhiteSpace
boolean isWhiteSpace() throws XmlPullParserException
- Throws:
XmlPullParserException
-
getNamespace
String getNamespace()
-
getName
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.
-
getAttributeCount
int getAttributeCount()
-
getAttributeNamespace
String getAttributeNamespace(int index)
-
getAttributeName
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
QName getAttributeQName(int index)
-
getAttributePrefix
String getAttributePrefix(int index)
-
getAttributeType
String getAttributeType(int index)
-
getAttributeValue
String getAttributeValue(int index)
-
getAttributeValue
String getAttributeValue(String namespace, String name)
-
getAttributeValue
default String getAttributeValue(String name)
-
getEventType
XmlPullParser.Event getEventType() throws XmlPullParserException
- Throws:
XmlPullParserException
-
next
XmlPullParser.Event next() throws IOException, XmlPullParserException
- Throws:
IOException
XmlPullParserException
-
nextText
String nextText() throws 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:
IOException
- in case of an IO error.XmlPullParserException
- in case of an XML pull parser error.
-
nextTag
XmlPullParser.TagEvent nextTag() throws IOException, XmlPullParserException
- Throws:
IOException
XmlPullParserException
-
supportsRoundtrip
boolean supportsRoundtrip()
-
-