hi all,
I'm writing an XML file from a DOM Document like this:
Source source = new DOMSource(doc);
Result result = new StreamResult(new File("settings.xml"));
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
While however it works, all XML tags are written on one line.
Is there any way I can change that behaviour so that there is
indentation and newlines in the file?
Thanks already
abigale_carson@yahoo.com - 20 Dec 2005 15:12 GMT
Check out this thread from comp.lang.java:
http://groups.google.com/group/comp.lang.java/browse_frm/thread/9045827b989a53f4
/2a8f942dd4a943a5?lnk=st&q=TransformerFactory+pretty-print&rnum=1&hl=en#2a8f942d
d4a943a5
Or, if it breaks,
http://linkfrog.net/dacn
Hope this helps,
Abigale
Chris Smith - 20 Dec 2005 16:00 GMT
> I'm writing an XML file from a DOM Document like this:
>
[quoted text clipped - 7 lines]
> Is there any way I can change that behaviour so that there is
> indentation and newlines in the file?
Not in the XML transformation APIs. If you switch to Xerces instead of
using generic JAXP code, then Xerces has an option to pretty-print XML.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation