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

Document.importNode() doesn't assign value of default attribute

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      sparc
    • OS:
      solaris_7
    • Verification:
      Verified

      Description

      Name: inR10064 Date: 10/27/2000



      JAXP 1.1 method
      org.w3c.dom.Document.importNode(Node importedNode, boolean deep)

      retains value of default attribute of imported element while importing
      document defines attribute for this element with the same name of attribute
      but another value (See test.java below). The method should return element with
      the attribute value that is defined in importing document.

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

      " importNode introduced in DOM Level 2
        ....
             ELEMENT_NODE
                Specified attribute nodes of the source element are imported, and
                the generated Attr nodes are attached to the generated Element.
                Default attributes are not copied, though if the document being imported
                into defines default attributes for this element name,
                those are assigned. "
                
        This bug presents in builds jaxp-1.1ea-b8, jaxp-1.1fcs-b9 and jaxp-1.1ea2-b10 and
      affects the new test in TCK JAXP 1.1
      api/org_w3c_dom/Document/ImportNodeTests.html#importNodeTest008.

      ------------------------------------test.java-----------------------------
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import java.io.ByteArrayInputStream;

      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 firstDoc = documentBuilder.parse(in);
              
                  data =
                      "<?xml version=\"1.0\" ?>" +
                      "<!DOCTYPE root [" +
                      "ELEMENT root ANY" +
                      "ATTLIST root c CDATA #FIXED \"qqq\"" +
                      "]>" +
                      "<root/>";
                  
                  in = new ByteArrayInputStream(data.getBytes());
                  Document secondDoc = documentBuilder.parse(in);
                  Element element = (Element)secondDoc.getElementsByTagName("root")
                                    .item(0);
                  
                  System.out.println("Before: " + element.getAttribute("c"));
                  element = (Element)firstDoc.importNode(element, false);
                  System.out.println("After: " + element.getAttribute("c"));
              } catch (Exception e) {
                  System.out.println("Unexpected " + e + " was thrown");
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion 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)

      Before: qqq
      After: qqq
      ---------------------------------------------------------------------------

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


      ###@###.### 2002-02-06

      Tested on Xerces2.0.0. Works Fine.
      ###@###.### 2003-08-12

        Attachments

          Activity

            People

            • Assignee:
              nbajajsunw Neeraj Bajaj (Inactive)
              Reporter:
              inevsunw Inev Inev (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: