Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] how to append to an xml file using jdom

awais hamid

2004-06-30

Replies:

Hello friends i am deeloping a semantic cache of xml queries and xml
documents
Here is a glimpse of my code in which i am creating an xml document with
following structure
- <queries>
<query>/books/book[price>300]/bookname</query>
</queries>

SAXBuilder saxobj=new SAXBuilder();
Element rootofquery = new Element("queries");
Element elementofquery = new Element("query");
Document doc1ofquery = new Document();

elementofquery.setText(query);


rootofquery.addContent(elementofquery);
doc1ofquery.addContent(rootofquery);

In the code given below i will be saving xml o queries.xml file

XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
File queryfile=new File("queries.xml");
FileOutputStream queryout=new FileOutputStream(queryfile);

    outputter.output(doc1ofquery, queryout);

But every time when this script executes the previus data is overwritten
which i dont want.

What should be done? to append to existing data instead of replacing it.

I would be thankful for ur replies

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.