• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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());
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic