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

com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.writeToString outputs double <?xml ...>

XMLWordPrintable

    • b72
    • generic, x86
    • generic, windows_xp
    • Verified

      com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.writeToString outputs double "<?xml version="1.0" encoding="UTF-16"?>" since JDK b71.
      b70 works ok.

      To reproduce problem run the following code

      ==========================================================================
      import java.io.*;
      import java.net.*;
      import java.security.*;
      import javax.xml.parsers.*;
      import org.w3c.dom.*;
      import org.w3c.dom.ls.*;
      import org.w3c.dom.traversal.NodeFilter;
      import org.xml.sax.*;


      public class filterTests {

          public static void main(String argv[]) {

              DOMImplementationLS implLS = null;
              String xml1 = "<?xml version=\"1.0\"?><ROOT><ELEMENT1><CHILD1/><CHILD1><COC1/></CHILD1></ELEMENT1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";

              Document doc = null;
              DocumentBuilder db = null;

      StringBufferInputStream is = new StringBufferInputStream(xml1);

              try {
                  db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                  doc = db.parse(is);
              } catch (Throwable t) {
                  t.printStackTrace();
      System.out.println("Failed " + t);
              }

              DOMImplementation impl = doc.getImplementation();
              implLS = (DOMImplementationLS) impl.getFeature("LS","3.0");

              LSParser parser = implLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,"http://www.w3.org/2001/XMLSchema");


              LSInput src = implLS.createLSInput();
              src.setStringData(xml1);

              LSSerializer writer = implLS.createLSSerializer();

      System.out.println("");
      System.out.println(writer.getClass().getName());

              // set filter
              writer.setFilter(
                  new LSSerializerFilter() {
                      public short acceptNode(Node enode) {
                          if (enode.getNodeName().startsWith("CHILD"))
                              return FILTER_REJECT;
                          return FILTER_ACCEPT;
                      }

                      public int getWhatToShow() {
                          return NodeFilter.SHOW_ALL;
                      }
                  }
              );

              Document doc2 = parser.parse(src);

              String res = writer.writeToString(doc2);

      System.out.println("");
      System.out.println("res " + res);

              System.out.println("OKAY");
          }
      }
      ==========================================================================

      Sample output:
      ==========================================================================
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b71)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b71, mixed mode)


      com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl

      res <?xml version="1.0" encoding="UTF-16"?>
      <?xml version="1.0" encoding="UTF-16"?>
      <ROOT><ELEMENT1/><ELEMENT2>test1</ELEMENT2></ROOT>
      OKAY
      ==========================================================================

            sreddysunw Sunitha Reddy (Inactive)
            idergali Ilya Dergalin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: