We help IT Professionals succeed at work.

The best programming way to create XML

jkteater
jkteater asked
on
In my code I need to create a XML of all the values I have in my dialog.  I have seen different ways to write a xml.  I have something about DOM.  I have seen code using a StringBuffer.  I have seen code using OutputStream writer.  What is the best and simplest way to write a XML
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
I think DOM is still the way to go, unless you have some very simple XML file
Awarded 2011
Awarded 2011

Commented:
In case of simnple structure of XML file you can write it directlky jsut like any file with FileWrioter
Awarded 2011
Awarded 2011
Commented:
If you want to write file represneting some jave object with complex nested structure then probably DOM will help - otherwise - just write plain file with tags and values - it would be easier
CERTIFIED EXPERT

Commented:
For writing XML we use the XOM library (http://www.xom.nu/).  It's a DOM style approach - you build up an object to represent the XML and then write it out with:

        Serializer serializer = new Serializer(out);
          serializer.setIndent(2) ;      // Make it human readable
          serializer.write(doc);
          serializer.flush();

Simple to work with and clean XML output.

Doug

Explore More ContentExplore courses, solutions, and other research materials related to this topic.