Android XmlPullParser Skip skipSubTree(final XmlPullParser pp)

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

Description

Skip sub tree that is currently porser positioned on.

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*/*from ww  w . j  av a  2 s  .  c om*/
 * 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 {
    /**
     * 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;
        }
    }

    public static void require(final XmlPullParser pp, final String tagName)
            throws XmlPullParserException, IOException {
        skipWhitespace(pp);

        pp.require(XmlPullParser.START_TAG, null, tagName);
    }

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

    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();
    }
}

Related

  1. skipCurrentTag(XmlPullParser parser)
  2. skipExit(final XmlPullParser pp)
  3. skipExit(final XmlPullParser pp, final String tagName)
  4. skipSubTree(XmlPullParser pp)
  5. skipSubTree(XmlPullParser pp)
  6. skipTag(XmlPullParser parser)
  7. skipWhitespace(final XmlPullParser pp)
  8. requireSkip(final XmlPullParser pp, final String tagName)