XML with java

hi allI want to save my data to a XML file, and then use a java program to write and read the data from the xml, but i never do that before, anyone can tell me how? thanx alot!
[197 byte] By [luckybar] at [2007-9-30 11:53:17]
# 1
There are plenty of tutorials on the subject at java.sun.com. I highly suggest you start there.
limeybrit9 at 2007-7-4 13:48:44 > top of Java-index,Administration Tools,Sun Connection...
# 2

Hi, I'm actually doing the same thing at work, so we can help each other out! well I am using JDOM. I found this on javaworld.com

Here's a class that reads an XML document and prints it in a nice, readable form:

import java.io.*;

import org.jdom.*;

import org.jdom.input.*;

import org.jdom.output.*;

public class PrettyPrinter {

public static void main(String[] args) {

// Assume filename argument

String filename = args[0];

try {

// Build the document with SAX and Xerces, no validation

SAXBuilder builder = new SAXBuilder();

// Create the document

Document doc = builder.build(new File(filename));

// Output the document, use standard formatter

XMLOutputter fmt = new XMLOutputter();

fmt.output(doc, System.out);

} catch (Exception e) {

e.printStackTrace();

}

}

}

all you need to do is to create a file in xml, and you're good to go.

sumama23 at 2007-7-4 13:48:44 > top of Java-index,Administration Tools,Sun Connection...
# 3
Thank you very much
luckybar at 2007-7-4 13:48:44 > top of Java-index,Administration Tools,Sun Connection...