> i need to now how i cant to convert a Java object to XML file
> it its very important to me , because i not yet found a tutorial thet
> give a good example to how implement .
Use java.beans.XMLEncoder (new in 1.4)
> Use java.beans.XMLEncoder (new in 1.4)
e.g.
<sscce>
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.beans.*;
/** Shows a simple example of saving objects as XML.
Requires Java 1.4+.
@author Andrew Thompson */
public class TestXMLWrite {
/** Writes this object as an XML file */
public static void writeObjectAsXML(Object o, String fileName)
throws FileNotFoundException {
File f = new File(fileName);
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(f)));
e.writeObject(o);
e.close();
}
public static void main(String args[]) throws Exception {
Button b = new Button("Open");
writeObjectAsXML(b, "button.xml");
JTree jt = new JTree();
writeObjectAsXML(jt, "tree.xml");
}
}
</sscce>
HTH
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology