Android XmlPullParser Value Get attr(final XmlPullParser pp, final String attrName)

Here you can find the source of attr(final XmlPullParser pp, final String attrName)

Description

attr

License

Open Source License

Declaration

public static String attr(final XmlPullParser pp, final String attrName) 

Method Source Code

//package com.java2s;
/*// ww  w . jav  a  2  s .com
 * For license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/).
 * According to www.xmlpull.org, this code is in the public domain.
 */

import org.xmlpull.v1.XmlPullParser;

public class Main {
    public static String attr(final XmlPullParser pp, final String attrName) {
        final String attr = optAttr(pp, attrName, null);

        if (attr != null)
            return attr;
        else
            throw new IllegalStateException("expecting attribute: "
                    + attrName);
    }

    public static String optAttr(final XmlPullParser pp,
            final String attrName, final String defaultValue) {
        final String attr = pp.getAttributeValue(null, attrName);

        if (attr != null) {
            final String trimmedAttr = attr.trim();

            if (trimmedAttr.length() > 0)
                return trimmedAttr;
        }

        return defaultValue;
    }
}

Related

  1. extractFirstChildTextIgnoreRest( XmlPullParser paramXmlPullParser)
  2. optAttr(final XmlPullParser pp, final String attrName, final String defaultValue)
  3. optFloatAttr(final XmlPullParser pp, final String attrName, final float defaultValue)
  4. optIntAttr(final XmlPullParser pp, final String attrName, final int defaultValue)
  5. optSkip(final XmlPullParser pp, final String tagName)
  6. copyXML(XmlPullParser xmlPullParser, XmlSerializer xmlSerializer)
  7. exit(final XmlPullParser pp, final String tagName)
  8. floatAttr(final XmlPullParser pp, final String attrName)
  9. intAttr(final XmlPullParser pp, final String attrName)