Android XmlPullParser Value Get optIntAttr(final XmlPullParser pp, final String attrName, final int defaultValue)

Here you can find the source of optIntAttr(final XmlPullParser pp, final String attrName, final int defaultValue)

Description

opt Int Attr

License

Open Source License

Declaration

public static int optIntAttr(final XmlPullParser pp,
            final String attrName, final int defaultValue) 

Method Source Code

//package com.java2s;
/*/*from   w w w .  j a v  a 2s  .  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 int optIntAttr(final XmlPullParser pp,
            final String attrName, final int defaultValue) {
        final String attr = optAttr(pp, attrName, null);
        if (attr != null)
            return Integer.parseInt(attr);
        else
            return defaultValue;
    }

    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. GetFullName(XmlPullParser reader)
  2. extractChildText(XmlPullParser paramXmlPullParser)
  3. extractFirstChildTextIgnoreRest( XmlPullParser paramXmlPullParser)
  4. optAttr(final XmlPullParser pp, final String attrName, final String defaultValue)
  5. optFloatAttr(final XmlPullParser pp, final String attrName, final float defaultValue)
  6. optSkip(final XmlPullParser pp, final String tagName)
  7. attr(final XmlPullParser pp, final String attrName)
  8. copyXML(XmlPullParser xmlPullParser, XmlSerializer xmlSerializer)
  9. exit(final XmlPullParser pp, final String tagName)