Two Laptop Bag
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: 19742

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
jQuery in Action, 3rd edition