GetAttributeNSpublic final class GetAttributeNS extends DOMTestCase The "getAttributeNS(namespaceURI,localName)" method retrieves an attribute
value by local name and NamespaceURI.
Retrieve the first "emp:address" element. The value returned by the
"getAttributeNS()" method should be the value "DISTRICT" since the attribute
has a default value. |
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 | testGetAttributeNS2()Runs the test case.
String namespaceURI = "http://www.nist.gov";
String localName = "district";
String qualifiedName = "emp:district";
Document doc;
Attr newAttribute;
NodeList elementList;
Element testAddr;
String attrValue;
doc = (Document) load("staffNS", builder);
newAttribute = doc.createAttributeNS(namespaceURI, qualifiedName);
elementList = doc.getElementsByTagName("emp:address");
testAddr = (Element) elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
testAddr.setAttributeNodeNS(newAttribute);
elementList = doc.getElementsByTagName("emp:address");
testAddr = (Element) elementList.item(0);
attrValue = testAddr.getAttributeNS(namespaceURI, localName);
assertEquals("throw_Equals", "", attrValue);
| public void | testGetAttributeNS3()
String namespaceURI = "http://www.nist.gov";
String localName = "domestic";
Document doc;
NodeList elementList;
Element testAddr;
String attrValue;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:address");
testAddr = (Element) elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
testAddr.removeAttributeNS(namespaceURI, localName);
attrValue = testAddr.getAttributeNS(namespaceURI, localName);
assertEquals("throw_Equals", "", attrValue);
| public void | testGetAttributeNS4()
String namespaceURI = "http://www.nist.gov";
String localName = "blank";
String qualifiedName = "emp:blank";
Document doc;
NodeList elementList;
Element testAddr;
String attrValue;
doc = (Document) load("staffNS", builder);
doc.createAttributeNS(namespaceURI, qualifiedName);
elementList = doc.getElementsByTagName("emp:address");
testAddr = (Element) elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
testAddr.setAttributeNS(namespaceURI, qualifiedName, "NewValue");
attrValue = testAddr.getAttributeNS(namespaceURI, localName);
assertEquals("throw_Equals", "NewValue", attrValue);
| public void | testGetAttributeNS5()
Document doc;
NodeList elementList;
Element testAddr;
String attrValue;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:address");
testAddr = (Element) elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
attrValue = testAddr.getAttributeNS("http://www.nist.gov", "domestic");
assertEquals("attrValue", "Yes", attrValue);
|
|