RemoveNamedItemNSpublic 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. |
Fields Summary |
---|
DOMDocumentBuilderFactory | factory | DocumentBuilder | builder |
Methods Summary |
---|
protected void | setUp()
super.setUp();
try {
factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
.getConfiguration2());
builder = factory.getBuilder();
} catch (Exception e) {
fail("Unexpected exception" + e.getMessage());
}
| protected void | tearDown()
factory = null;
builder = null;
super.tearDown();
| public void | testRemoveNamedItemNS1()Runs the test case.
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 void | testRemoveNamedItemNS2()
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);
}
|
|