Android XmlPullParser Read ReadSubtreeString(XmlPullParser reader)

Here you can find the source of ReadSubtreeString(XmlPullParser reader)

Description

Read Subtree String

License

Open Source License

Declaration

public static String ReadSubtreeString(XmlPullParser reader)
            throws XmlPullParserException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Main {
    public static String ReadSubtreeString(XmlPullParser reader)
            throws XmlPullParserException, IOException {
        if (reader == null)
            throw new NullPointerException();
        // Return if not on a start element tag
        if (reader.getEventType() != XmlPullParser.START_TAG)
            return "";
        StringBuilder builder = new StringBuilder();
        int depth = GetDepth(reader);
        while (GetDepth(reader) != depth
                || reader.getEventType() != XmlPullParser.END_TAG) {
            reader.next();/*w  w  w .j  a  va  2 s. c om*/
            if (reader.getEventType() != XmlPullParser.END_TAG) {
                if (reader.getEventType() == XmlPullParser.ENTITY_REF
                        || reader.getEventType() == XmlPullParser.CDSECT
                        || reader.getEventType() == XmlPullParser.TEXT) {
                    builder.append(reader.getText());
                }
            }
        }
        return builder.toString();
    }

    public static int GetDepth(XmlPullParser reader) {
        if (reader == null)
            throw new NullPointerException();
        return Math.max(reader.getDepth() - 1, 0);
    }
}

Related

  1. readValueXml(XmlPullParser parser, String[] name)
  2. readValueXml(XmlPullParser parser, String[] name)
  3. readValueXml(XmlPullParser parser, String[] name)
  4. readValueXml(XmlPullParser parser, String[] name)
  5. Read(XmlPullParser parser)