how to write a XML file 2003-02-13 - By Keppel Yin
Hi,
I want to construct a XML document in memory and then write it to a file. Here is my code trying to do it.
+++++++++++++++++++++++++++++++++++++++++++++++++++ FileWriter output = new FileWriter("c:\test.xml"); OutputFormat of = new OutputFormat("xml","UTF-8",true);
XMLSerializer serializer = new XMLSerializer(output, of);
Document dom = new DocumentImpl();
Element root = dom.createElement("Target"); root.setAttribute("name", sAppName); root.setAttribute("path", sPath);
Element admin = dom.createElement("Administrator"); admin.setAttribute("name", sName); admin.setAttribute("email", sEmail); root.appendChild(admin);
serializer.serialize(dom); output.close();
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I always get a empty file, the size of c:\test.xml is zero.
Can someone shed some light on how to do it correctly?
Thanks a lot,
Keppel
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|