Xerces 1.0.2: Comments nodes are not printed properly by the serializer IMHO. The following is the patch I've made for org.apache.xml.serialize.BaseMarkupSerializer:
Index: BaseMarkupSerializer.java =================================================================== RCS file: /home/cvspublic/xml-xerces/java/src/org/apache/xml/serialize/BaseMarkupSerializer.java,v retrieving revision 1.10 diff -r1.10 BaseMarkupSerializer.java 519c519,520 < indent(); --- > //indent(); > breakLine(); 521c522,523 < unindent(); --- > breakLine(); > //unindent(); Before the patch, the output file looks like: <?xml version="1.0" encoding="UTF-8"?> <root> <ele1> <ele2 attr1="attrval1"/><!-- This is a comment --></ele1> </root> After the patch, the output file looks like: <?xml version="1.0" encoding="UTF-8"?> <root> <ele1> <ele2 attr1="attrval1"/> <!-- This is a comment --> </ele1> </root> However, the bad news is comment that span multiple lines still is printed on a single line. I couldn't figure out how to fix this.