File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Writing XML File via Java Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Writing XML File via Java Program" Watch "Writing XML File via Java Program" New topic

Writing XML File via Java Program

Anbarasu Selvaraj

Joined: Mar 07, 2006
Posts: 21
Hi Friends, It's regarding writing xml file via java program.

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);

In the above code it's displaying data's.

Now i want to write this data's to xml file. (How to process transformer value)

Please help me on this. Thanks.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

So you want to write it to a file instead of System.out? Then just change System.out to something which outputs to that file instead of to the console.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Use Xstream API .

Try it .

Save India From Corruption - Anna Hazare.
I agree. Here's the link:
subject: Writing XML File via Java Program
It's not a secret anymore!