-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
6
-
generic
-
generic
LSSerialiser.write() produces an incorrect output.
Details:
While serializing following XML Document:
-------------------------------
<?xml version=\"1.0\"?>
<ROOT>
<ELEMENT1>
</ELEMENT1>
<ELEMENT2>
</ELEMENT2>
</ROOT>
-------------------------------
we get the following output:
-------------------------------
<?xml version="1.0" encoding="UTF-16"?>
<?xml version="1.0" encoding="UTF-16"?>
<ROOT>
<ELEMENT1/>
<ELEMENT2/>
</ROOT>
-------------------------------
Document itself is OK, but <?xml...?> header is
printed twice.
Run following example to simply reproduce this failure:
---------8<----------Test.java----------------------
import org.w3c.dom.ls.*;
import java.io.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
class Test {
public static void main(String args[]) {
String xml = "<?xml version=\"1.0\"?><ROOT><ELEMENT1></ELEMENT1><ELEMENT2></ELEMENT2></ROOT>";
DocumentBuilder builder = null;
Document doc = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
try {
doc = builder.parse(new StringBufferInputStream(xml));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
DOMImplementation impl = doc.getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS","3.0");
LSInput src = implLS.createLSInput();
src.setStringData(xml);
LSParser parser = implLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,"http://www.w3.org/2001/XMLSchema");
LSSerializer writer = implLS.createLSSerializer();
Document xmldoc = parser.parse(src);
String result = writer.writeToString(xmldoc);
System.out.println(result);
}
}
---------8<----------Test.java----------------------
We have a number of JCK test failures due to this bug.
For example: api/org_w3c/dom/ls/LSSerializer/index.html#write[write0001]
Details:
While serializing following XML Document:
-------------------------------
<?xml version=\"1.0\"?>
<ROOT>
<ELEMENT1>
</ELEMENT1>
<ELEMENT2>
</ELEMENT2>
</ROOT>
-------------------------------
we get the following output:
-------------------------------
<?xml version="1.0" encoding="UTF-16"?>
<?xml version="1.0" encoding="UTF-16"?>
<ROOT>
<ELEMENT1/>
<ELEMENT2/>
</ROOT>
-------------------------------
Document itself is OK, but <?xml...?> header is
printed twice.
Run following example to simply reproduce this failure:
---------8<----------Test.java----------------------
import org.w3c.dom.ls.*;
import java.io.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
class Test {
public static void main(String args[]) {
String xml = "<?xml version=\"1.0\"?><ROOT><ELEMENT1></ELEMENT1><ELEMENT2></ELEMENT2></ROOT>";
DocumentBuilder builder = null;
Document doc = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
try {
doc = builder.parse(new StringBufferInputStream(xml));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
DOMImplementation impl = doc.getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS","3.0");
LSInput src = implLS.createLSInput();
src.setStringData(xml);
LSParser parser = implLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,"http://www.w3.org/2001/XMLSchema");
LSSerializer writer = implLS.createLSSerializer();
Document xmldoc = parser.parse(src);
String result = writer.writeToString(xmldoc);
System.out.println(result);
}
}
---------8<----------Test.java----------------------
We have a number of JCK test failures due to this bug.
For example: api/org_w3c/dom/ls/LSSerializer/index.html#write[write0001]
- duplicates
-
JDK-6387435 com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.writeToString outputs double <?xml ...>
-
- Closed
-