[jdom-interest] how to append to an xml file using jdom
Laurent Bihanic
laurent.bihanic at atosorigin.com
Thu Jul 1 00:47:39 PDT 2004
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
More information about the jdom-interest
mailing list