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

Phil Weighill-Smith phil.weighill-smith at volantis.com
Thu Jul 1 00:52:46 PDT 2004


Surely the right way to do this is to read the existing file into a JDOM
document (and if the file doesn't exist just create the basic document
structure), add your query nodes into the required location in the
document then write the whole document back out?

Phil :n.

On Thu, 2004-07-01 at 08:47, Laurent Bihanic wrote:

> Why not simply using
>     FileOutputStream queryout=new FileOutputStream(queryfile, true);
> to open the file in append mode?
> 
> Be careful when concatenating several XML documents into a single file. The 
> result is not well-formed XML as a file can only contain one document. You 
> won't be able to parse the generated file.
> 
> Laurent
> 
> 
> awais hamid wrote:
> 
> > 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
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
Phil Weighill-Smith <phil.weighill-smith at volantis.com>
Volantis Systems
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20040701/74ef8cb8/attachment.htm


More information about the jdom-interest mailing list