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

SetAttributeNS

public final class SetAttributeNS extends DOMTestCase
The "setAttributeNS(namespaceURI,qualifiedName,Value)" method raises a INVALID_CHARACTER_ERR DOMException if the specified prefix contains an illegal character. Attempt to add a new attribute on the first employee node. An exception should be raised since the "qualifiedName" has an invalid character.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INVALID_CHARACTER_ERR'])
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAttrNS
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration1());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    
protected voidtearDown()

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestSetAttributeNS1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        String namespaceURI = "http://www.nist.gov";
        String qualifiedName = "emp:qual?name";
        Document doc;
        NodeList elementList;
        Node testAddr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("employee");
        testAddr = elementList.item(0);

        {
            boolean success = false;
            try {
                ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                        qualifiedName, "newValue");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
            }
            assertTrue("throw_INVALID_CHARACTER_ERR", success);
        }
    
public voidtestSetAttributeNS10()

        String namespaceURI = "http://www.example.gov";
        Document doc;
        NodeList elementList;
        Node testAddr;
        doc = (Document) load("hc_staff", builder);
        elementList = doc.getElementsByTagName("em");
        testAddr = elementList.item(0);

        {
            boolean success = false;
            try {
                ((Element) /* Node */testAddr).setAttributeNS(namespaceURI, "",
                        "newValue");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestSetAttributeNS2()

        String namespaceURI = "http://www.nist.gov";
        String qualifiedName = "emp:";
        Document doc;
        NodeList elementList;
        Node testAddr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("emp:employee");
        testAddr = elementList.item(0);

        {
            boolean success = false;
            try {
                ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                        qualifiedName, "newValue");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestSetAttributeNS4()

        Document doc;
        NodeList elementList;
        Node testAddr;
        Attr addrAttr;
        String resultAttr;
        String resultNamespaceURI;
        String resultLocalName;
        String resultPrefix;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("emp:address");
        testAddr = elementList.item(0);
        assertNotNull("empAddrNotNull", testAddr);
        ((Element) /* Node */testAddr).setAttributeNS("http://www.nist.gov",
                "newprefix:zone", "newValue");
        addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
                "http://www.nist.gov", "zone");
        resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
                "http://www.nist.gov", "zone");
        assertEquals("attrValue", "newValue", resultAttr);
        resultNamespaceURI = addrAttr.getNamespaceURI();
        assertEquals("nsuri", "http://www.nist.gov", resultNamespaceURI);
        resultLocalName = addrAttr.getLocalName();
        assertEquals("lname", "zone", resultLocalName);
        resultPrefix = addrAttr.getPrefix();
        assertEquals("prefix", "newprefix", resultPrefix);
    
public voidtestSetAttributeNS5()

        String localName = "newAttr";
        String namespaceURI = "http://www.newattr.com";
        String qualifiedName = "emp:newAttr";
        Document doc;
        NodeList elementList;
        Node testAddr;
        
        String resultAttr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("emp:address");
        testAddr = elementList.item(0);
        assertNotNull("empAddrNotNull", testAddr);
        ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                qualifiedName, "<newValue>");
        resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
                namespaceURI, localName);
        assertEquals("throw_Equals", "<newValue>", resultAttr);
    
public voidtestSetAttributeNS6()

        String namespaceURI = "http://www.nist.gov";
        String qualifiedName = "xml:qualifiedName";
        Document doc;
        NodeList elementList;
        Node testAddr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("employee");
        testAddr = elementList.item(0);

        {
            boolean success = false;
            try {
                ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                        qualifiedName, "newValue");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestSetAttributeNS7()

        String namespaceURI = "http://www.nist.gov";
        String qualifiedName = "xmlns";
        Document doc;
        NodeList elementList;
        Node testAddr;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("employee");
        testAddr = elementList.item(0);

        {
            boolean success = false;
            try {
                ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                        qualifiedName, "newValue");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestSetAttributeNS9()

        String localName = "newAttr";
        String namespaceURI = "http://www.newattr.com";
        String qualifiedName = "emp:newAttr";
        Document doc;
        NodeList elementList;
        Node testAddr;
        Attr addrAttr;
        String resultAttr;
        String resultNamespaceURI;
        String resultLocalName;
        String resultPrefix;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("emp:address");
        testAddr = elementList.item(0);
        assertNotNull("empAddrNotNull", testAddr);
        ((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
                qualifiedName, "newValue");
        addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
                namespaceURI, localName);
        resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
                namespaceURI, localName);
        assertEquals("attrValue", "newValue", resultAttr);
        resultNamespaceURI = addrAttr.getNamespaceURI();
        assertEquals("nsuri", "http://www.newattr.com", resultNamespaceURI);
        resultLocalName = addrAttr.getLocalName();
        assertEquals("lname", "newAttr", resultLocalName);
        resultPrefix = addrAttr.getPrefix();
        assertEquals("prefix", "emp", resultPrefix);