Android XmlPullParser Move to Next nextLong(XmlPullParser parser, String tag)

Here you can find the source of nextLong(XmlPullParser parser, String tag)

Description

next Long

Declaration

public static Long nextLong(XmlPullParser parser, String tag)
            throws XmlPullParserException, IOException 

Method Source Code

//package com.java2s;
import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Main {
    public static Long nextLong(XmlPullParser parser, String tag)
            throws XmlPullParserException, IOException {
        parser.require(XmlPullParser.START_TAG, null, tag);

        Long value = Long.parseLong(readText(parser));

        parser.require(XmlPullParser.END_TAG, null, tag);

        return value;
    }/*  w ww .  j  av a2  s. co  m*/

    private static String readText(XmlPullParser parser)
            throws XmlPullParserException, IOException {
        String value = null;

        while (parser.next() != XmlPullParser.END_TAG) {
            if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
                throw new XmlPullParserException(
                        "reached unexpected end of document");
            } else if (parser.getEventType() != XmlPullParser.TEXT) {
                continue;
            }
            String text = parser.getText();

            value = textOf(text);
        }

        return value;
    }

    private static String textOf(String text) {
        return text.trim().replace("\r", "");
    }
}

Related

  1. nextElementWithin(XmlPullParser parser, int outerDepth)
  2. nextEndTag(XmlPullParser pp)
  3. nextEndTag(XmlPullParser pp)
  4. nextEndTag(XmlPullParser pp, String namespace, String name)
  5. nextEndTag(XmlPullParser pp, String namespace, String name)
  6. nextStartTag(XmlPullParser pp)
  7. nextStartTag(XmlPullParser pp)
  8. nextStartTag(XmlPullParser pp, String name)
  9. nextStartTag(XmlPullParser pp, String name)