File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes need help in appending data to an existing xml file 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 "need help in appending data to an existing xml file" Watch "need help in appending data to an existing xml file" New topic
Author

need help in appending data to an existing xml file

Pooja Oza
Greenhorn

Joined: Apr 01, 2009
Posts: 21
I have an xml file having data, and want to add more to that file when a button is pressed in swing frame-

the xml file is like this -

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<FDTracker>
<FDdetails>
<fdnumber>8</fdnumber>
<bankname>BOA</bankname>
<beneficiaryname>test</beneficiaryname>
<rateofinterest>5</rateofinterest>
<amount>400</amount>
<maturityamount>6000</maturityamount>
</FDdetails>
// want to insert data here
<FDdetails>
.
.
.
</FDdetails>

</FDTracker>


how can i do this because every time the button is clicked, i want to store the data from the textfields of the window to an xml file , but i also want the previous data and the current one too.
I want to write the new data in between the <FDdetails> tag each time i click the button.

Can someone please help me with this? Completely exhausted searching on net for tutorials but no success.

I would really appreciate your help.




Thanks,
Pooja

Thanks,

Pooja Oza
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

I think DOM parser can do this.

SCJP 5, SCWCD 5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
There are various APIs that can be used to alter an existing XML document: JAXP/DOM, XOM, JDOM, dom4j, ...


Ping & DNS - my free Android networking tools app
mahammad gouse
Greenhorn

Joined: Jul 04, 2010
Posts: 15
hi,
the DOM parser is suitable one for this.
first of of parse the XML file.
we have a method in DOM API, which it adds exactly before the paticular tag.


bye

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
<nitpicking>I feel compelled to point out that a parser can't alter anything - parsing XML means the act of reading it. DOM does more than just parse XML, though - it has methods to alter the resulting DOM tree. (And, if one wanted to be even more exacting, DOM doesn't actually do parsing at all- it relies on an underlying SAX parser to do that.)</nitpicking>
Pooja Oza
Greenhorn

Joined: Apr 01, 2009
Posts: 21
Thanks everyone, i will now concentrate on using the DOM parser and try to do my program. Thank you all once again for your help.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
<extended-nitpicking>Actually, the Simple API for XML (SAX) also does not do any "parsing." It is an API that receives callbacks from an actual parser, e.g. Apache Xerces. Both DOM and SAX are programming API, they are not parsers.</extended-nitpicking>
 
GeeCON Prague 2014
 
subject: need help in appending data to an existing xml file