Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to append data

 
pavan Mudundi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic