writing xml : layout

T

Tomba

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
 
C

Chris Smith

Tomba said:
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?

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top