Code example for XmlPullParser

Methods: getNamespace, getNamespaceCount, getNamespacePrefix, getNamespaceUri

0
 
        assertEquals(0, parser.getNamespaceCount(0));
    } 
 
    private void checkNamespacesInOne(XmlPullParser parser) throws XmlPullParserException {
        assertEquals(2, parser.getNamespaceCount(1));
 
        // Prefix for default namespace is null. 
        assertNull(parser.getNamespacePrefix(0));
        assertEquals("ns:default", parser.getNamespaceUri(0));
 
        assertEquals("n1", parser.getNamespacePrefix(1));
        assertEquals("ns:1", parser.getNamespaceUri(1));
 
        assertEquals("ns:default", parser.getNamespace(null));
 
        // KXML returns null. 
        // assertEquals("ns:default", parser.getNamespace("")); 
    } 
 
    private void checkNamespacesInTwo(XmlPullParser parser) throws XmlPullParserException {
        // These should still be valid. 
        checkNamespacesInOne(parser);
 
        assertEquals(3, parser.getNamespaceCount(2));
 
        // Default ns should still be in the stack 
        assertNull(parser.getNamespacePrefix(0));
        assertEquals("ns:default", parser.getNamespaceUri(0));
    } 
 
    public void testNamespaces() { 
        try { 
            NamespaceHandler handler = new NamespaceHandler();