Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 12761
    
    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
 
Similar Threads
how to use insertBefore method
problem in getting xpath of each node.
About XML serialization(Sas Jacobs what you conclude after reading this?)
how to remove a child (using JDOM)
Java code to append data into a existing xml file