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

NamedNodeMapRemoveNamedItemNS

public final class NamedNodeMapRemoveNamedItemNS extends DOMTestCase
The method removeNamedItemNS removes a node specified by local name and namespace Retreive an attribute node and then remove from the NamedNodeMap. Verify if the attribute node was actually remove from the node map.
author
IBM
author
Neil Delima
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D58B193

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
public void_testRemoveNamedItemNS4()

        Document doc;
        NamedNodeMap attributes;
        Node element;
        Attr attribute;

        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("*", "employee");
        element = elementList.item(0);
        attributes = element.getAttributes();
        attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "xmlns");
        attribute = (Attr) attributes.getNamedItemNS(
                "http://www.w3.org/2000/xmlns/", "xmlns");
        assertNull("namednodemapremovenameditemns04_1", attribute);
        attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "dmstc");
        attribute = (Attr) attributes.getNamedItemNS(
                "http://www.w3.org/2000/xmlns/", "dmstc");
        assertNull("namednodemapremovenameditemns04_2", attribute);
    
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;
        NamedNodeMap attributes;
        Node element;
        Attr attribute;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "address");
        element = elementList.item(1);
        attributes = element.getAttributes();
        attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
                "domestic");
        attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov",
                "domestic");
        assertNull("namednodemapremovenameditemns01", attribute);
    
public voidtestRemoveNamedItemNS3()

        Document doc;
        NamedNodeMap attributes;
        Node element;
        Attr attribute;

        Attr attribute1;
        Attr attribute2;
        String nodeName;
        doc = (Document) load("staffNS", builder);
        element = doc.createElementNS("http://www.w3.org/DOM/Test", "root");
        attribute1 = doc
                .createAttributeNS("http://www.w3.org/DOM/L1", "L1:att");
        ((Element) /* Node */element).setAttributeNodeNS(attribute1);
        attribute2 = doc
                .createAttributeNS("http://www.w3.org/DOM/L2", "L2:att");
        ((Element) /* Node */element).setAttributeNodeNS(attribute2);
        attributes = element.getAttributes();
        attribute = (Attr) attributes.removeNamedItemNS(
                "http://www.w3.org/DOM/L1", "att");
        attribute = (Attr) attributes.getNamedItemNS(
                "http://www.w3.org/DOM/L2", "att");
        nodeName = attribute.getNodeName();
        assertEquals("namednodemapremovenameditemns02", "L2:att", nodeName);
    
public voidtestRemoveNamedItemNS6()

        Document doc;
        NamedNodeMap attributes;
        Node element;

        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "employee");
        element = elementList.item(1);
        attributes = element.getAttributes();

        {
            boolean success = false;
            try {
                attributes.removeNamedItemNS("http://www.Nist.gov", "domestic");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_FOUND_ERR);
            }
            assertTrue("throw_NOT_FOUND_ERR", success);
        }
    
public voidtestRemoveNamedItemNS7()

        Document doc;
        NamedNodeMap attributes;
        Node element;

        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "employee");
        element = elementList.item(1);
        attributes = element.getAttributes();

        {
            boolean success = false;
            try {
                attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_FOUND_ERR);
            }
            assertTrue("throw_NOT_FOUND_ERR", success);
        }
    
public voidtestRemoveNamedItemNS8()

        Document doc;
        NamedNodeMap attributes;
        Element element;

        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "address");
        element = (Element) elementList.item(1);
        attributes = element.getAttributes();
        element.removeAttributeNS("http://www.nist.gov", "domestic");

        {
            boolean success = false;
            try {
                attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_FOUND_ERR);
            }
            assertTrue("throw_NOT_FOUND_ERR", success);
        }
    
public voidtestRemoveNamedItemNS9()

        Document doc;
        NamedNodeMap attributes;
        NamedNodeMap newAttributes;
        Element element;
        Attr attribute;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "address");
        element = (Element) elementList.item(1);
        attributes = element.getAttributes();
        attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
                "domestic");
        newAttributes = element.getAttributes();
        attribute = (Attr) newAttributes.getNamedItemNS("http://www.nist.gov",
                "domestic");
        assertNull("namednodemapremovenameditemns09", attribute);