Code example for XmlPullParser

Methods: getAttributeCount, getAttributeName, getAttributeValue, getDepth, getEventType, getName, getText, next

0
        parser.setInput(new ByteArrayInputStream(snippet.getBytes()), "UTF-8");
        validate(parser);
    } 
 
    static void validate(XmlPullParser parser) throws Exception {
        assertEquals(XmlPullParser.START_DOCUMENT, parser.getEventType());
        assertEquals(0, parser.getDepth());
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals(1, parser.getDepth());
        assertEquals("dagny", parser.getName());
        assertEquals(1, parser.getAttributeCount());
        assertEquals("dad", parser.getAttributeName(0));
        assertEquals("bob", parser.getAttributeValue(0));
        assertEquals("bob", parser.getAttributeValue(null, "dad"));
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals(1, parser.getDepth());
        assertEquals("hello", parser.getText());
        assertEquals(XmlPullParser.END_TAG, parser.next());
        assertEquals(1, parser.getDepth());
        assertEquals("dagny", parser.getName());
        assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
        assertEquals(0, parser.getDepth());
    } 
 
    public void testNextAfterEndDocument() throws Exception { 
        XmlPullParser parser = newPullParser();
        parser.setInput(new StringReader("<foo></foo>"));