-
Bug
-
Resolution: Fixed
-
P3
-
7, 7u4
-
b18
-
x86
-
linux, linux_ubuntu
-
Verified
Test program:
---%<---
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class JAXP7u4Regression {
public static void main(String[] args) throws Exception {
String data =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<r>\n" +
" <e/>\n" +
"</r>\n";
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(data)));
TransformerFactory tf = TransformerFactory.newInstance();
String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
"xmlns:xalan='http://xml.apache.org/xslt' " +
"exclude-result-prefixes='xalan'>" +
"<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
"<xsl:template match='@*|node()'>" +
"<xsl:copy>" +
"<xsl:apply-templates select='@*|node()'/>" +
"</xsl:copy>" +
"</xsl:template>" +
"</xsl:stylesheet>";
Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
Source source = new DOMSource(doc);
Result result = new StreamResult(System.out);
t.transform(source, result);
}
private JAXP7u4Regression() {}
}
---%<---
Output in 7u3 (b04; Ubuntu, 32-bit JVM):
<?xml version="1.0" encoding="UTF-8"?>
<r>
<e/>
</r>
vs. 7u4 (b14):
<?xml version="1.0" encoding="UTF-8"?><r>
<e/>
</r>
Note the missing newline between the XML declaration and the root element.
---%<---
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class JAXP7u4Regression {
public static void main(String[] args) throws Exception {
String data =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<r>\n" +
" <e/>\n" +
"</r>\n";
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(data)));
TransformerFactory tf = TransformerFactory.newInstance();
String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
"xmlns:xalan='http://xml.apache.org/xslt' " +
"exclude-result-prefixes='xalan'>" +
"<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
"<xsl:template match='@*|node()'>" +
"<xsl:copy>" +
"<xsl:apply-templates select='@*|node()'/>" +
"</xsl:copy>" +
"</xsl:template>" +
"</xsl:stylesheet>";
Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
Source source = new DOMSource(doc);
Result result = new StreamResult(System.out);
t.transform(source, result);
}
private JAXP7u4Regression() {}
}
---%<---
Output in 7u3 (b04; Ubuntu, 32-bit JVM):
<?xml version="1.0" encoding="UTF-8"?>
<r>
<e/>
</r>
vs. 7u4 (b14):
<?xml version="1.0" encoding="UTF-8"?><r>
<e/>
</r>
Note the missing newline between the XML declaration and the root element.
- duplicates
-
JDK-7166588 JDK7 update 4 changed XML indenting behavior
- Closed
- relates to
-
JDK-5064280 XSLT output type XML does not honor {http://xml.apache.org/xslt}indent-amount in
- Resolved
-
JDK-8035437 Xerces Update: xml/serialize/DOMSerializerImpl
- Resolved
-
JDK-8249867 XML declaration is not followed by a newline
- Closed