-
Bug
-
Resolution: Fixed
-
P4
-
11.0.5
-
b18
-
x86
-
os_x
A DESCRIPTION OF THE PROBLEM :
If I try to transform from a StreamSource of an XML file having a comment between XML declaration and xml root element to a StaxResult (constructed from a XMLStreamWriter) I run into a
javax.xml.transform.TransformerException: org.xml.sax.SAXException: Can not output XML declaration, after other output has already been done.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See java code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The transformation does not throw an exception
ACTUAL -
The transformation throws a javax.xml.transform.TransformerException
---------- BEGIN SOURCE ----------
package org.apache.jackrabbit.vault.fs.io;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
public static void main(String[] args) throws IOException, XMLStreamException, TransformerException {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!--comment-->\n" +
"<root />\n";
try (Reader reader = new StringReader(xml);
OutputStream out = new ByteArrayOutputStream()) {
XMLOutputFactory factory = XMLOutputFactory.newFactory();
XMLStreamWriter writer = factory.createXMLStreamWriter(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
StreamSource source = new StreamSource(reader);
StAXResult result = new StAXResult(writer);
t.transform(source, result);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
If I try to transform from a StreamSource of an XML file having a comment between XML declaration and xml root element to a StaxResult (constructed from a XMLStreamWriter) I run into a
javax.xml.transform.TransformerException: org.xml.sax.SAXException: Can not output XML declaration, after other output has already been done.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See java code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The transformation does not throw an exception
ACTUAL -
The transformation throws a javax.xml.transform.TransformerException
---------- BEGIN SOURCE ----------
package org.apache.jackrabbit.vault.fs.io;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
public static void main(String[] args) throws IOException, XMLStreamException, TransformerException {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!--comment-->\n" +
"<root />\n";
try (Reader reader = new StringReader(xml);
OutputStream out = new ByteArrayOutputStream()) {
XMLOutputFactory factory = XMLOutputFactory.newFactory();
XMLStreamWriter writer = factory.createXMLStreamWriter(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
StreamSource source = new StreamSource(reader);
StAXResult result = new StAXResult(writer);
t.transform(source, result);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8241711 Transformer produces incorrect results when StAXResult is used
- Open