• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Save XML Document to File?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has got to be much simpler than it seems. I have a org.w3c.dom.Document in memory. I want to save it as an XML document to a file. This has to be easy. But I can't find it anywhere.
HELP?
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was confused by an old Microsoft API which simply had a write method, that saved the XML to file.
Here's the right way:
OutputFormat fmt = new OutputFormat();
StringWriter sw = new StringWriter ();
XMLSerializer serial = new XMLSerializer(sw, fmt);
serial.serialize(doc);
System.out.println(stringOut.toString());
 
reply
    Bookmark Topic Watch Topic
  • New Topic