Android Utililty Methods XmlPullParser Value Get

List of utility methods to do XmlPullParser Value Get

Description

The list of methods to do XmlPullParser Value Get are organized into topic(s).

Method

StringgetAttributeByName(XmlPullParser xpp, String name)
Returns the XML attribute by name, not as fast as using attribute indexes but much more durable in case of future api changes
for (int i = 0; i < xpp.getAttributeCount(); i++)
    if (name.equalsIgnoreCase(xpp.getAttributeName(i)))
        return xpp.getAttributeValue(i);
return null;
StringgetAttributeValue(XmlPullParser pp, String name)
Return value of attribute with given name and no namespace.
return pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, name);
StringgetAttributeValue(XmlPullParser pp, String name)
Return value of attribute with given name and no namespace.
return pp.getAttributeValue(XmlPullParser.NO_NAMESPACE, name);
MapgetAttributes( XmlPullParser pullParser)
get Attributes
Map<String, String> attributes = new HashMap<String, String>(
        pullParser.getAttributeCount());
for (int i = 0; i < pullParser.getAttributeCount(); i++) {
    attributes.put(pullParser.getAttributeName(i),
            pullParser.getAttributeValue(i));
return attributes;
MapgetAttributes( XmlPullParser pullParser, String namespace, String elementName, String attributeName, String attributeValue)
get Attributes
Map<String, String> attributes = null;
boolean shouldEndParse = false;
if (pullParser != null) {
    if (!TextUtils.isEmpty(elementName)) {
        int event = pullParser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT
                && !shouldEndParse) {
            switch (event) {
...
StringgetPIData(XmlPullParser pp)
Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'
int eventType;
try {
    eventType = pp.getEventType();
} catch (XmlPullParserException ex) {
    throw new IllegalStateException(
            "could not determine parser state: " + ex
                    + pp.getPositionDescription());
if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) {
    throw new IllegalStateException(
            "parser must be on processing instruction and not "
                    + XmlPullParser.TYPES[eventType]
                    + pp.getPositionDescription());
final String PI = pp.getText();
int pos = -1;
for (int i = 0; i < PI.length(); i++) {
    if (isS(PI.charAt(i))) {
        pos = i;
    } else if (pos > 0) {
        return PI.substring(i);
return "";
StringgetPIData(XmlPullParser pp)
Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'
int eventType;
try {
    eventType = pp.getEventType();
} catch (XmlPullParserException ex) {
    throw new IllegalStateException(
            "could not determine parser state: " + ex
                    + pp.getPositionDescription());
if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) {
    throw new IllegalStateException(
            "parser must be on processing instruction and not "
                    + XmlPullParser.TYPES[eventType]
                    + pp.getPositionDescription());
final String PI = pp.getText();
int pos = -1;
for (int i = 0; i < PI.length(); i++) {
    if (isS(PI.charAt(i))) {
        pos = i;
    } else if (pos > 0) {
        return PI.substring(i);
return "";
StringgetPITarget(XmlPullParser pp)
Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'
int eventType;
try {
    eventType = pp.getEventType();
} catch (XmlPullParserException ex) {
    throw new IllegalStateException(
            "could not determine parser state: " + ex
                    + pp.getPositionDescription());
if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) {
    throw new IllegalStateException(
            "parser must be on processing instruction and not "
                    + XmlPullParser.TYPES[eventType]
                    + pp.getPositionDescription());
final String PI = pp.getText();
for (int i = 0; i < PI.length(); i++) {
    if (isS(PI.charAt(i))) {
        return PI.substring(0, i);
return PI;
StringgetPITarget(XmlPullParser pp)
Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'
int eventType;
try {
    eventType = pp.getEventType();
} catch (XmlPullParserException ex) {
    throw new IllegalStateException(
            "could not determine parser state: " + ex
                    + pp.getPositionDescription());
if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) {
    throw new IllegalStateException(
            "parser must be on processing instruction and not "
                    + XmlPullParser.TYPES[eventType]
                    + pp.getPositionDescription());
final String PI = pp.getText();
for (int i = 0; i < PI.length(); i++) {
    if (isS(PI.charAt(i))) {
        return PI.substring(0, i);
return PI;
StringgetRequiredAttributeValue(XmlPullParser pp, String namespace, String name)
Read attribute value and return it or throw exception if current element does not have such attribute.
String value = pp.getAttributeValue(namespace, name);
if (value == null) {
    throw new XmlPullParserException("required attribute " + name
            + " is not present");
} else {
    return value;