FileDocCategorySizeDatePackage
GetNamedItemNS.javaAPI DocAndroid 1.5 API4535Wed May 06 22:41:06 BST 2009tests.org.w3c.dom

GetNamedItemNS

public final class GetNamedItemNS extends DOMTestCase
The "getNamedItemNS(namespaceURI,localName)" method for a NamedNodeMap should return a node specified by localName and namespaceURI Retrieve a list of elements with tag name "address". Access the second element from the list and get its attributes. Try to retrieve the attribute node with local name "domestic" and namespace uri "http://www.usa.com" with method getNamedItemNS(namespaceURI,localName).
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-F68D095

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration2());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    
protected voidtearDown()

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestGetNamedItemNS1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        Document doc;
        NodeList elementList;
        Node testEmployee;
        NamedNodeMap attributes;
        Attr domesticAttr;
        String attrName;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("address");
        testEmployee = elementList.item(1);
        attributes = testEmployee.getAttributes();
        domesticAttr = (Attr) attributes.getNamedItemNS("http://www.usa.com",
                "domestic");
        attrName = domesticAttr.getNodeName();
        assertEquals("attrName", "dmstc:domestic", attrName);
    
public voidtestGetNamedItemNS2()

        String namespaceURI = "http://www.usa.com";
        String localName = "domest";
        Document doc;
        NodeList elementList;
        Node testEmployee;
        NamedNodeMap attributes;
        Attr newAttr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("address");
        testEmployee = elementList.item(1);
        attributes = testEmployee.getAttributes();
        newAttr = (Attr) attributes.getNamedItemNS(namespaceURI, localName);
        assertNull("throw_Null", newAttr);