Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to write xml to a file

843834Dec 18 2003 — edited Dec 19 2003

Hi

I'm developing a program that will retrieve data from a db and will need to write it to a xml file.

Actually I'm using an example that someone gave me to write xml to stdout:
  TransformerFactory transFact = TransformerFactory.newInstance();
            Transformer trans = transFact.newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            StringWriter sw = new StringWriter();
            Result result = new StreamResult(sw);
            try {
                trans.transform(new DOMSource(doc), result);
            } catch (TransformerException te) {
                System.out.println(te.getMessageAndLocation());
                throw te;
            }

            System.out.println(sw.toString());
How could I write this to a file ?


Thanks in advance

<xl>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 16 2004
Added on Dec 18 2003
6 comments
149 views