Hi Stanimir. The Xalan serializer doesn't know about whether the serialized XML will be used in the the future as an external general parsed entity and included in yet another XML file.
It is possible that the XML will be included next to a text node that is not all whitespace and the extra whitespace that we inject after the XML header would be included next to non-whitespace text and become part of that text node, modifying it. Extra whitespace added for indentation is done in ignorable locations, but this particular one (just after the header) might not be ignored. Added indentation or extra whitespace before the document element is not always correct, so Xalan doesn't do it. There is no Xalan specific option to control this behavior. - Brian - - - - - - - - - - - - - - - - - - - - Brian Minchau, Ph.D. XSLT Development, IBM Toronto (780) 431-2633 e-mail: [EMAIL PROTECTED] [EMAIL PROTECTED] et To 01/23/2008 06:46 xalan-j-users@xml.apache.org AM cc Subject Output a new line after the XML declaration using indent="yes" [resending my original message as it didn't appear in the list, trying out 4 times.] Using the example serialization code (see at the end) and the built-in Sun's Java 1.4 JAXP implementation I get a result file: <?xml version="1.0" encoding="UTF-8"?> <doc> <para>foo bar</para> </doc> However when I plug-in Xalan 2.7.1 I get a result file: <?xml version="1.0" encoding="UTF-8"?><doc> <para>foo bar</para> </doc> Is there a way to make the document element appear on a new line after the XML declaration when using the indent="yes" output option? -----XMLSerializationTest.java import java.io.File; import java.io.FileOutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; public class XMLSerializationTest { static final String XALAN_INDENT_AMOUNT = "{http://xml.apache.org/xslt}" + "indent-amount"; public static void main(String[] args) throws Exception { File resultFile = new File("test.xml"); SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance(); TransformerHandler handler = stf.newTransformerHandler(); Transformer transformer = handler.getTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(XALAN_INDENT_AMOUNT, "2"); handler.setResult(new StreamResult( new FileOutputStream(resultFile))); Attributes noAtts = new AttributesImpl(); String text = "foo bar"; handler.startDocument(); handler.startElement("", "", "doc", noAtts); handler.startElement("", "", "para", noAtts); handler.characters(text.toCharArray(), 0, text.length()); handler.endElement("", "", "para"); handler.endElement("", "", "doc"); handler.endDocument(); System.out.println("Done."); } } -----XMLSerializationTest.java-- -- Stanimir