[jdom-interest] saving document as a file

Brett McLaughlin brett.mclaughlin at lutris.com
Sat Jun 3 16:16:05 PDT 2000


Dan Olson wrote:
> 
> Okay, so I've got an xml file; as per the example in the article, I convert
> that into a Document object, which I can then read, modify, etc.  How do I
> convert the modified Document back into a file?  Am I missing something
> obvious?
> 
>       File xmlFile = new File("exampleFile.xml");
> 
>       // Build the document with SAX and Xerces, validation if true
>       SAXBuilder builder = new SAXBuilder(true);
> 
>       // Create the document
>       Document document = builder.build(xmlFile);
> 
>       // do stuff with the document
>          .
>          .
>          .
>          .
>       // save the modifed document as a file (how?)

No - just part two of the article ;-)  Part 1 was reading, part two was
writing ;-) And of course, part two isn't out yet.

Check out XMLOutputter (org.jdom.output.XMLOutputter) for outputting to
a File, Stream, etc - there's also an example in
samples/org/jdom/examples/io/SAXBuilderDemo writing to an OutputStream -
you can also output to a FileOutputStream.

Hope that helps.

-Brett

> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 
http://www.lutris.com
http://www.enhydra.org



More information about the jdom-interest mailing list