Code example for XmlPullParser

Methods: getAttributeName, getAttributeValue, getName, next, setFeature, setInput

0
 
public abstract class PullParserTest extends TestCase {
 
    public void testAttributeNoValueWithRelaxed() throws Exception { 
        XmlPullParser parser = newPullParser();
        parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
        parser.setInput(new StringReader("<input checked></input>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("input", parser.getName());
        assertEquals("checked", parser.getAttributeName(0));
        assertEquals("checked", parser.getAttributeValue(0));
    } 
 
    public void testAttributeUnquotedValueWithRelaxed() throws Exception { 
        XmlPullParser parser = newPullParser();
        parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
        parser.setInput(new StringReader("<input checked=true></input>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("input", parser.getName());
        assertEquals("checked", parser.getAttributeName(0));
        assertEquals("true", parser.getAttributeValue(0));