• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

need help in appending data to an existing xml file

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think DOM parser can do this.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are various APIs that can be used to alter an existing XML document: JAXP/DOM, XOM, JDOM, dom4j, ...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
There's a way to do it better - find it. -Edison. A better tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic