Formatting XML output of attributes and elements
How would I go about formatting an XML Document text output so that the elements are properly indented, and every attribute is displayed on it's own line. The reason I want to accomplish this is we want a readable XML format output of a Java object with many attributes which we want to be able to do diffs on when we create new versions, and right now all the XML element's attributes are displayed on one line.
Currently I'm using the javax.xml.transform.Transformer to transform a org.w3c.dom.Document as a javax.xml.transform.dom.DOMSource to a StreamResult. I'm currently able to specify that elements are indented using the OutputKeys.INDENT.
Is there any way for me to create some kind of Java output handler that I can inject and have it format the XML text? I don't think XSLT would work in this situation because the object graphs that are being serialized are to numerous and complex to easily define in an XSLT (especially just to format the XML text).
My XML output code looks like this (is there any way to do a noformat syntax to post XML and java code to these forums?):
The XML I'm outputting looks like this:
What I'd like the XML to look like is to have line breaks before each attribute and to indent them past the element, like:
Message was edited by: dougnukem