1 package tests.org.w3c.dom; 2 3 import org.w3c.dom.Element; 4 import org.w3c.dom.Attr; 5 import org.w3c.dom.Document; 6 7 import javax.xml.parsers.DocumentBuilder; 8 9 /** 10 * The method removeAttributeNS removes an attribute by local name and namespace 11 * URI. Create a new element and add a new attribute node to it. Remove the 12 * attribute node using the removeAttributeNodeNS method. Check if the attribute 13 * was remove by invoking the hasAttributeNS method on the element and check if 14 * it returns false. 15 * 16 * @author IBM 17 * @author Neil Delima 18 * @see <a 19 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS</a> 20 */ 21 public final class ElementRemoveAttributeNS extends DOMTestCase { 22 23 DOMDocumentBuilderFactory factory; 24 25 DocumentBuilder builder; 26 setUp()27 protected void setUp() throws Exception { 28 super.setUp(); 29 try { 30 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 31 .getConfiguration1()); 32 builder = factory.getBuilder(); 33 } catch (Exception e) { 34 fail("Unexpected exception" + e.getMessage()); 35 } 36 } 37 tearDown()38 protected void tearDown() throws Exception { 39 factory = null; 40 builder = null; 41 super.tearDown(); 42 } 43 44 /** 45 * Runs the test case. 46 * 47 * @throws Throwable 48 * Any uncaught exception causes test to fail 49 */ testRemoveAttributeNS()50 public void testRemoveAttributeNS() throws Throwable { 51 Document doc; 52 Element element; 53 boolean state; 54 Attr attribute; 55 56 doc = (Document) load("staff", builder); 57 element = doc.createElementNS("http://www.w3.org/DOM", "elem"); 58 attribute = doc.createAttributeNS( 59 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 60 element.setAttributeNodeNS(attribute); 61 element.removeAttributeNS( 62 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 63 state = element.hasAttributeNS( 64 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 65 assertFalse("elementremoveattributens01", state); 66 } 67 68 } 69