aspose file tools*
The moose likes XML and Related Technologies and the fly likes how to append data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to append data" Watch "how to append data" New topic
Author

how to append data

pavan Mudundi
Greenhorn

Joined: Mar 10, 2008
Posts: 1
Thanks for your reply.
I'll make you more clear what I want.
If this is my xml file
<books>
<person>
<first>Tom</first>
<last>Cruise</last>
<age>45</age>
</person>
</books>

Now when I append some data, I should have my previous data in it. Like
<books>
<person>
<first>Tom</first>
<last>Cruise</last>
<age>45</age>
</person>
<person>
<first>Tom</first>
<last>Hanks</last>
<age>48</age>
</person>
</books>

This is how I want. But my data gets overwritten with previous data and I show up as
<books>
<person>
<first>Tom</first>
<last>Hanks</last>
<age>48</age>
</person>
</books>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
If your original file has a complete XML document in it, there is no simple way to just append more text because what results is an illegal XML document.
You might treat this as a purely text problem by reading the original file to locate and remove the closing root element </books> and adding more text.

Or you might read the original into memory as a DOM and append data using the DOM methods.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to append data