This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help in appending data to an existing xml file

 
Pooja Oza
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 196
Java Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think DOM parser can do this.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are various APIs that can be used to alter an existing XML document: JAXP/DOM, XOM, JDOM, dom4j, ...
 
mahammad gouse
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic