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

Imported element has attribute defined default in original document

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.1
    • 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 default attribute of imported element while importing document
      doesn't define such attribute for this element (See test.java below).

        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#importNodeTest007.

      ------------------------------------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();

                  Document firstDoc = documentBuilder.newDocument();

                  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 secondDoc = documentBuilder.parse(in);
              
                  Element el = (Element)secondDoc.getElementsByTagName("root").item(0);
              
                  Element element = (Element)firstDoc.importNode(el, false);
                  
                  System.out.println(element.hasAttribute("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)

      true
      ---------------------------------------------------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: