Android XmlPullParser Read readNumber(XmlPullParser parser)

Here you can find the source of readNumber(XmlPullParser parser)

Description

read Number

Declaration

public static int readNumber(XmlPullParser parser) throws IOException,
            XmlPullParserException 

Method Source Code

//package com.java2s;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;

public class Main {
    public static int readNumber(XmlPullParser parser) throws IOException,
            XmlPullParserException {/*from   w  ww .j a v a  2 s. c  o  m*/
        try {
            String text = readText(parser);
            return Integer.parseInt(text);
        } catch (NumberFormatException ex) {
            throw new XmlPullParserException("Expected number");
        }
    }

    public static String readText(XmlPullParser parser) throws IOException,
            XmlPullParserException {
        String result = "";
        if (parser.next() == XmlPullParser.TEXT) {
            result = parser.getText();
            parser.nextTag();
        }
        return result;
    }
}

Related

  1. readIntAttribute(XmlPullParser in, String name)
  2. readIntAttribute(XmlPullParser in, String name, int defaultValue)
  3. readInteger(XmlPullParser parser, String ns, String tag)
  4. readLongAttribute(XmlPullParser in, String name)
  5. readLongAttribute(XmlPullParser in, String name, long defaultValue)
  6. readString(XmlPullParser parser, String ns, String tag)
  7. readStringArray(XmlPullParser parser, String tagName, String delimiter)
  8. readStringAttribute(XmlPullParser in, String name)
  9. readText(XmlPullParser parser)