1 2 /* 3 This Java source file was generated by test-to-java.xsl 4 and is a derived work from the source document. 5 The source document contained the following notice: 6 7 8 9 Copyright (c) 2001-2004 World Wide Web Consortium, 10 (Massachusetts Institute of Technology, Institut National de 11 Recherche en Informatique et en Automatique, Keio University). All 12 Rights Reserved. This program is distributed under the W3C's Software 13 Intellectual Property License. This program is distributed in the 14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 PURPOSE. 17 18 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21 */ 22 23 package org.w3c.domts.level2.core; 24 25 import org.w3c.dom.*; 26 27 28 import org.w3c.domts.DOMTestCase; 29 import org.w3c.domts.DOMTestDocumentBuilderFactory; 30 31 32 33 /** 34 * The "setAttributeNS(namespaceURI,qualifiedName,value)" method adds a new attribute. 35 * If an attribute with the same local name and namespace URI is already present 36 * on the element, its prefix is changed to be the prefix part of the "qualifiedName", 37 * and its vale is changed to be the "value" paramter. 38 * null value if no previously existing Attr node with the 39 * same name was replaced. 40 * 41 * Add a new attribute to the "emp:address" element. 42 * Check to see if the new attribute has been successfully added to the document 43 * by getting the attributes value, namespace URI, local Name and prefix. 44 * @author NIST 45 * @author Mary Brady 46 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAttrNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAttrNS</a> 47 */ 48 public final class setAttributeNS09 extends DOMTestCase { 49 50 /** 51 * Constructor. 52 * @param factory document factory, may not be null 53 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 54 */ 55 public setAttributeNS09(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 56 super(factory); 57 58 // 59 // check if loaded documents are supported for content type 60 // 61 String contentType = getContentType(); 62 preload(contentType, "staffNS", true); 63 } 64 65 /** 66 * Runs the test case. 67 * @throws Throwable Any uncaught exception causes test to fail 68 */ 69 public void runTest() throws Throwable { 70 String localName = "newAttr"; 71 String namespaceURI = "http://www.newattr.com"; 72 String qualifiedName = "emp:newAttr"; 73 Document doc; 74 NodeList elementList; 75 Node testAddr; 76 Attr addrAttr; 77 String resultAttr; 78 String resultNamespaceURI; 79 String resultLocalName; 80 String resultPrefix; 81 doc = (Document) load("staffNS", true); 82 elementList = doc.getElementsByTagName("emp:address"); 83 testAddr = elementList.item(0); 84 assertNotNull("empAddrNotNull", testAddr); 85 ((Element) /*Node */testAddr).setAttributeNS(namespaceURI, qualifiedName, "newValue"); 86 addrAttr = ((Element) /*Node */testAddr).getAttributeNodeNS(namespaceURI, localName); 87 resultAttr = ((Element) /*Node */testAddr).getAttributeNS(namespaceURI, localName); 88 assertEquals("attrValue", "newValue", resultAttr); 89 resultNamespaceURI = addrAttr.getNamespaceURI(); 90 assertEquals("nsuri", "http://www.newattr.com", resultNamespaceURI); 91 resultLocalName = addrAttr.getLocalName(); 92 assertEquals("lname", "newAttr", resultLocalName); 93 resultPrefix = addrAttr.getPrefix(); 94 assertEquals("prefix", "emp", resultPrefix); 95 } 96 /** 97 * Gets URI that identifies the test. 98 * @return uri identifier of test 99 */ 100 public String getTargetURI() { 101 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNS09"; 102 } 103 /** 104 * Runs this test from the command line. 105 * @param args command line arguments 106 */ 107 public static void main(final String[] args) { 108 DOMTestCase.doMain(setAttributeNS09.class, args); 109 } 110 } 111 112