GetNamedItemNSpublic 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). |
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 | testGetNamedItemNS1()Runs the test case.
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 void | testGetNamedItemNS2()
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);
|
|