Android XmlPullParser Search requireEndDocument(final XmlPullParser pp)

Here you can find the source of requireEndDocument(final XmlPullParser pp)

Description

require End Document

License

Open Source License

Declaration

public static void requireEndDocument(final XmlPullParser pp)
            throws XmlPullParserException, IOException 

Method Source Code

//package com.java2s;
/*//from   w  ww. ja  va  2s . c o m
 * 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 java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Main {
    public static void requireEndDocument(final XmlPullParser pp)
            throws XmlPullParserException, IOException {
        skipWhitespace(pp);

        if (pp.getEventType() != XmlPullParser.END_DOCUMENT)
            throw new IllegalStateException("expecting end of document: "
                    + pp.getPositionDescription());
    }

    private static void skipWhitespace(final XmlPullParser pp)
            throws XmlPullParserException, IOException {
        if (pp.getEventType() == XmlPullParser.START_DOCUMENT)
            pp.next();
        if (pp.getEventType() == XmlPullParser.TEXT && pp.isWhitespace())
            pp.next();
    }

    public static void next(final XmlPullParser pp)
            throws XmlPullParserException, IOException {
        skipSubTree(pp);
        pp.next();
    }

    /**
     * Skip sub tree that is currently porser positioned on. <br>
     * NOTE: parser must be on START_TAG and when funtion returns parser will be positioned on corresponding END_TAG
     */
    public static void skipSubTree(final XmlPullParser pp)
            throws XmlPullParserException, IOException {
        pp.require(XmlPullParser.START_TAG, null, null);

        int level = 1;
        while (level > 0) {
            final int eventType = pp.next();
            if (eventType == XmlPullParser.END_TAG)
                --level;
            else if (eventType == XmlPullParser.START_TAG)
                ++level;
        }
    }
}

Related

  1. beginDocument(XmlPullParser parser, String firstElementName)
  2. matchNameSpaceUri( XmlPullParser paramXmlPullParser, String paramString)
  3. matches(XmlPullParser pp, int type, String namespace, String name)
  4. matches(XmlPullParser pp, int type, String namespace, String name)
  5. test(final XmlPullParser pp, final String tagName)
  6. findChildToDepth(XmlPullParser parser, int parentDepth, String namespaceName, String name)