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

GetAttributeNS

public 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.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElGetAttrNS
see
http://www.w3.org/Bugs/Public/show_bug.cgi?id=238

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

throws
Throwable Any uncaught exception causes test to fail

        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 voidtestGetAttributeNS3()

        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 voidtestGetAttributeNS4()

        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 voidtestGetAttributeNS5()

        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);