Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4386142

NamedNodeMap.removeNamedItem removes attribute with default value

    XMLWordPrintable

Details

    • 1.1fcs
    • sparc
    • solaris_7

    Description



      Name: inR10064 Date: 11/04/2000


        JAXP 1.1 method org.w3c.dom.NamedNodeMap.removeNamedItem(String name)
      removes an attribute with default value from the map instead of replacing
      it with a copy (See test.java below).

        Definition of the method in p. 1.2 "Fundamental Interfaces" of DOM Level 2 Core
      (http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#ID-1780488922)
      says:

      " removeNamedItem
           Removes a node specified by name. When this map contains the attributes
           attached to an element, if the removed attribute is known to have a
           default value, an attribute immediately appears containing the default value
           as well as the corresponding namespace URI, local name, and prefix
           when applicable. "

      This bug presents in builds jaxp-1.1ea-b8, jaxp-1.1fcs-b9 and jaxp-1.1ea2-b10
      and affects the test in TCK JAXP 1.1

      api/com/sun/xml/tests/dom/NamedNodeMapTest.html#removeNamedItemAttr
           
      ------------------------------------test.java-----------------------------
      import org.w3c.dom.Document;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import java.io.ByteArrayInputStream;
      import org.w3c.dom.Element;
      import org.w3c.dom.NamedNodeMap;

      public class test {
          
          public static void main(String argv[]) {
              
              try {
                  DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
                                                    .newDocumentBuilder();

                  String data =
                      "<?xml version=\"1.0\" ?>" +
                      "<!DOCTYPE root [" +
                      "<!ELEMENT root ANY>" +
                      "<!ATTLIST root c CDATA #FIXED \"xxx\">" +
                      "]>" +
                      "<root/>";
              
                  ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());

                  Document document = documentBuilder.parse(in);
                  
                  Element root = document.getDocumentElement();
                  
                  NamedNodeMap attrs = root.getAttributes();
                  
                  System.out.println(attrs.getClass().getName());
                  
                  System.out.println("Before: " + attrs.item(0).getNodeName());
                  
                  attrs.removeNamedItem("c");
                  
                  String name = (attrs.item(0) == null) ?
                                null :
                                attrs.item(0).getNodeName();
                  
                  System.out.println("After: " + name);
                  
              } catch (Exception e) {
                  System.out.println("Unexpected " + e + " was thrown");
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion -cp .:jaxp1.1/jaxp.jar:jaxp1.1/crimson.jar test
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      org.apache.crimson.tree.AttributeSet
      Before: c
      After: null

      % java -showversion -cp .:jaxp1.0.1/jaxp.jar:jaxp1.0.1/parser.jar test
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      com.sun.xml.tree.AttributeSet
      Before: c
      After: c
      ---------------------------------------------------------------------------

      ======================================================================

      Attachments

        Activity

          People

            egoei Edwin Goei (Inactive)
            inevsunw Inev Inev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: