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

DTD comments appear in DOM as a child of Document Node

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2.0
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      19-April-2002

      The DTD comments should not appear in DOM as a child of Document Node.

      This bug can always be reproduced using xercesImpl.jar from b15-2002-04-17 build and the following program:

      ---------------------------------------------------------------
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import java.io.ByteArrayInputStream;
      import org.w3c.dom.Document;
      import org.w3c.dom.Node;
      import org.apache.xml.serialize.XMLSerializer;
      import org.apache.xml.serialize.OutputFormat;

      public class DTDComments {
      public static void main(String[] args) throws Exception {
                  String data =
                      "<?xml version=\"1.0\" ?>" +
                      "<!DOCTYPE root [" +
                      "<!ELEMENT root ANY>" +
                      "<!-- DTD comment -->" +
                      "]>" +
                      "<root><!-- comment in instance --><child>data</child></root>";

      ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      //dbf.setIgnoringComments(true);
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(in);
      Node node = doc.getDocumentElement();
      OutputFormat format = new OutputFormat((Document)doc);
      XMLSerializer ser = new XMLSerializer(System.out, format);
      System.out.println("********Serialize********");
      ser.serialize((Document)doc);
      System.out.println("\n\nDone");
      }
      }
      ---------------------------------------------------------------
      Output:
      ********Serialize********
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE root [<!ELEMENT root ANY>
      ]>
      <!-- DTD comment --><root><!-- comment in instance --><child>data</child></root>

      Done
      ---------------------------------------------------------------
      ###@###.###
      19-April-2002

        Attachments

          Activity

            People

            • Assignee:
              duke J. Duke (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: