aspose file tools*
The moose likes XML and Related Technologies and the fly likes Append a new entry in existing XML file using JAXB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Append a new entry in existing XML file using JAXB" Watch "Append a new entry in existing XML file using JAXB" New topic
Author

Append a new entry in existing XML file using JAXB

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi friends,

We are using XML's to read and write data's instead of hitting into DB. Now the thing is whenever a data is posted to form we are able to create the new XML, but what we need is instead of creating new XML that data has to be appended to the existing file. Say i have Main.xml which has around 50 entries in it. If a user post the values, it has to be appended to that end of file, instead of read the file and copy all to new file and save it. How can it be done?

Please guys i need your help
Thanks in advance.


Never try to be a hard-worker. Be a smart-worker.
My Blog
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18860
    
    8

Well, first of all, appending something to an XML file (i.e. adding it at the end, after the end tag of the root element) makes that document be not well-formed. So that isn't what you want to do. You want to insert this "entry" (which I suppose is some kind of element) before the end tag of the root element.

And XML is just text. So the way to do that is to generate a new document. You do that by reading the old document and writing out a modified version of it. You can't modify it in place. Besides you mentioned JAXB. JAXB definitely doesn't work by modifying existing files.

Apparently you're saying that your "need" is to modify the existing document in place. Well, you can't do that. So you'll have to review this so-called need and find out what the basis is for it. Then you'll have to examine that basis, whatever it might be, and address it properly. Often requirements like this come from people who don't know what they are talking about, so be prepared for that possibility.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Append a new entry in existing XML file using JAXB