Hi Dick, I ran the program that you point to with the URL and got your results.
For this input: String xml = "<root>\n\n\n<child1>text</child1> <child2>text</child2></root>"; For Xalan serializer and then Xerces serializer I get this: Program started Xalan serializer will be used <?xml version="1.0" encoding="UTF-16"?><root> <child1>text</child1> <child2>text</child2> </root> Program started Xerces serializer will be used <?xml version="1.0" encoding="UTF-16"?> <root> <child1>text</child1> <child2>text</child2> </root> The differences here are due to the fact that in the past the Xalan serializer has decided that the output XML file could be used as an external general parsed entity and included in yet another XML file. As such we don't know where it will be included and the extra newline that Xerces inserts after the XML header may be included next to non-whitespace text and become part of that text node. Added indentation or not, extra whitespace before the document element is not always correct, so Xalan doesn't do it. I looked at the code recently and saw that the DOM3 save support does indeed choose to indent 3 spaces per indentation level, and this code was contributed by to Xalan by people on the Xerces team, so I don't know why Xerces indents by 4 spaces. This difference is not important, there is no "right" way to do indentation, it depends on implementation. Then to add some whitespace, for this input: String xml = "<root>\n\n\n<child1>text</child1> <child2>text</child2></root>"; Program started Xalan serializer will be used <?xml version="1.0" encoding="UTF-16"?><root> <child1>text</child1> <child2>text</child2> </root> Program started Xerces serializer will be used <?xml version="1.0" encoding="UTF-16"?> <root> <child1>text</child1> <child2>text</child2> </root> Again Xalan does not inject any whitespace between the xml header and the document element, for the same reasons as given before. I'm not sure about the other whitespace differences. It looks like Xalan has decided that it won't add whitespace to existing whitespace and effectively does no indentation. Xerces serializer however rips out the whitespace from the document being serialized and replaces it with nicer looking whitespace. I'm not sure if that is OK to do that, perhaps someone from Xerces will comment on the differences. (Michael?) - Brian - - - - - - - - - - - - - - - - - - - - Brian Minchau, Ph.D. XSLT Development, IBM Toronto e-mail: [EMAIL PROTECTED] Dick Deneer <[EMAIL PROTECTED] eydevelopment.com To > xalan-j-users@xml.apache.org cc 02/19/2007 07:40 AM Subject Fomatting question serializing DOM with pretty-print I build a DOM with the following xml : <root><child1>text</child1><child2>text</child2></root> After serializing using the xalan serializer with the pretty-print option I get: <?xml version="1.0" encoding="UTF-16"?><root> <child1>text</child1> <child2>text</child2> </root> So the opening of the root is also in the first line. Second when I put in carriage returns or spaces, this effects the formatting seriously. For instance when I build a DOM with: <root>\n\n\n<child1>text</child1> <child2>text</child2></root> After serializing I get: <?xml version="1.0" encoding="UTF-16"?><root> <child1>text</child1> <child2>text</child2> </root> In all the cases the xerces serializer returns: <?xml version="1.0" encoding="UTF-16"?> <root> <child1>text</child1> <child2>text</child2> </root> Can you tell me if this behaviour i right? http://www.nabble.com/file/6633/TestSerializer.java TestSerializer.java -- View this message in context: http://www.nabble.com/Fomatting-question-serializing-DOM-with-pretty-print-tf3252607.html#a9041632 Sent from the Xalan - J - Users mailing list archive at Nabble.com.