Android XmlPullParser Read readStringArray(XmlPullParser parser, String tagName, String delimiter)

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

Description

Reads a String[] from the next xml tag

Parameter

Parameter Description
parser The parser to read the String from
tagName the name of the tag that contains the String Array
delimiter Regular expression delimiter for the text to create the String Array

Exception

Parameter Description
IOException an exception
XmlPullParserException an exception

Declaration

public static String[] readStringArray(XmlPullParser parser,
        String tagName, String delimiter) 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;

    /**/* w  w  w .  ja v a2s . c  om*/
     * 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 Array
     * @param delimiter Regular expression delimiter for the text to create the String Array
     * @throws IOException
     * @throws XmlPullParserException
     */
    public static String[] readStringArray(XmlPullParser parser,
            String tagName, String delimiter) throws IOException,
            XmlPullParserException {

        parser.require(XmlPullParser.START_TAG, NAMESPACE, tagName);
        String[] values = new String[0];
        if (parser.next() == XmlPullParser.TEXT) {
            String text = parser.getText();
            values = text.split(delimiter);
            parser.next();
        }
        parser.require(XmlPullParser.END_TAG, NAMESPACE, tagName);
        return values;
    }
}

Related

  1. readInteger(XmlPullParser parser, String ns, String tag)
  2. readLongAttribute(XmlPullParser in, String name)
  3. readLongAttribute(XmlPullParser in, String name, long defaultValue)
  4. readNumber(XmlPullParser parser)
  5. readString(XmlPullParser parser, String ns, String tag)
  6. readStringAttribute(XmlPullParser in, String name)
  7. readText(XmlPullParser parser)
  8. readText(XmlPullParser parser)
  9. readText(XmlPullParser parser)