Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parsing and value storage

 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • 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.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic