Code example for XmlPullParser

Methods: getText, next, nextTag, require

0
 * @author Philipp Ullmann 
 * XML parsing helper methods. 
 */ 
public abstract class XMLParser { 
    protected String readText(final XmlPullParser parser, final String tagName) throws XmlPullParserException, IOException {
        parser.require(XmlPullParser.START_TAG,
                       null, 
                       tagName);
         
        final String value = readText(parser);
         
        parser.require(XmlPullParser.END_TAG,
                       null, 
                       tagName);
         
        return value;
    } 
     
    protected String readText(final XmlPullParser parser) throws IOException, XmlPullParserException {
        String result = null;
         
        if (parser.next() == XmlPullParser.TEXT) {
            result = parser.getText();
            parser.nextTag();
        } 
         
        return result;
    }