You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Keppel Yin <Ke...@microfocus.com> on 2003/02/13 22:41:52 UTC
how to write a XML file
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@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org