Hi,

        Looks like you're not adding your root element to your document.

        Chris


-----Original Message-----
From: Keppel Yin [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 13, 2003 1:42 PM
To: [EMAIL PROTECTED]
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to