Android XmlPullParser Read readBool(XmlPullParser parser, String tagName)

Here you can find the source of readBool(XmlPullParser parser, String tagName)

Description

Reads boolean from the next xml tag

Parameter

Parameter Description
parser The parser to read the boolean from
tagName the name of the tag that contains the boolean

Declaration

public static boolean readBool(XmlPullParser parser, String tagName)
        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 final String NAMESPACE = null;

    /**/*from w  w w.j  a v  a 2 s.  c  om*/
     * Reads boolean from the next xml tag
     *
     * @param parser  The parser to read the boolean from
     * @param tagName the name of the tag that contains the boolean
     */
    public static boolean readBool(XmlPullParser parser, String tagName)
            throws IOException, XmlPullParserException {
        return readText(parser, tagName).equals("true");
    }

    /**
     * Reads a String from the next xml tag
     *
     * @param parser  The parser to read the String from
     * @param tagName the name of the tag that contains the String
     */
    public static String readText(XmlPullParser parser, String tagName)
            throws XmlPullParserException, IOException {

        String result = "";
        parser.require(XmlPullParser.START_TAG, NAMESPACE, tagName);
        if (parser.next() == XmlPullParser.TEXT) {
            result = parser.getText();
            parser.nextTag();
        }
        parser.require(XmlPullParser.END_TAG, NAMESPACE, tagName);
        return result;
    }
}

Related

  1. readAttribute(XmlPullParser parser, String tag, String attributeName)
  2. readBitmapAttribute(XmlPullParser in, String name)
  3. readBitmapAttribute(XmlPullParser in, String name)
  4. readBooleanAttribute(XmlPullParser in, String name)
  5. readBooleanAttribute(XmlPullParser in, String name)
  6. readBooleanAttribute(XmlPullParser in, String name, boolean defaultValue)
  7. readByteArrayAttribute(XmlPullParser in, String name)