• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

XML parsing and value storage

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to parse XML file using DOM parser and store it and need to do some calculations and again have put those values in XML. can any help me reg this.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per your requirement, please check JAXB (Java API for XML Binding) which exactly fits in.

In precise, JAXB as the term indicates, helps you to get the XML contents in terms of equivalent Java Objects and also to represent the Java objects back into XML representation.

When you have the Java object equivalence, you are free to do any changes to the content you want! Then you can convert back them into XML using the same JAXB.

The processes are called Marshalling and UnMarshalling.

This tutorial is an excellent one which gives you enough information right from the basics.

You can also look into the online documentation for the same.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parsing to the DOM is a lot simpler than parsing with JAXB. Note the difference: Parsing described in the standard APIs gives you the W3C DOM, a graph of standardized generic objects that represent XML bits and pieces. Parsing with JAXB gives you a graph of non-standard objects that have classes and field names that match the tags in the XML. I would personally walk a long ways to avoid JAXB on most days, but sometimes it pays off.

Either way, you can modify the graph of objects and generate a new XML string. Now the ease of use goes the other way ... the DOM is a pain to work with, while the custom Java objects you get from JAXB might more feel like normal Java work.

There is an XML forum here at the ranch. Maybe scroll down there and ask for examples. Let us know how you make out!
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the inputs Stam.

As you said, i have suggested JAXB for a simpler efforts to get back the XML back after modifying the contents.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic