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

RemoveNamedItemNS

public final class RemoveNamedItemNS extends DOMTestCase
The "removeNamedItemNS(namespaceURI,localName)" method for a NamedNodeMap should remove 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 remove the attribute node with local name "domestic" and namespace uri "http://www.usa.com" with method removeNamedItemNS(namespaceURI,localName). Check to see if the node has been removed.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-1074577549

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 voidtestRemoveNamedItemNS1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        Document doc;
        NodeList elementList;
        Node testAddress;
        NamedNodeMap attributes;
        Attr newAttr;
        Node removedNode;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("address");
        testAddress = elementList.item(1);
        attributes = testAddress.getAttributes();
        removedNode = attributes.removeNamedItemNS("http://www.usa.com",
                "domestic");
        assertNotNull("retval", removedNode);
        newAttr = (Attr) attributes.getNamedItem("dmstc:domestic");
        assertNull("nodeRemoved", newAttr);
    
public voidtestRemoveNamedItemNS2()

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

        {
            boolean success = false;
            try {
                attributes.removeNamedItemNS(namespaceURI,
                        localName);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_FOUND_ERR);
            }
            assertTrue("throw_NOT_FOUND_ERR", success);
        }