• 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
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Need help in coding

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
I am novice to sax and dom parsers. I have to convert a simple xml file to java object and then convert the java object back to xml for ex:
i want to convert simple.xml

<addressbook>
<person>
<fistname>james</firstname>
<lastname>bond</lastname>
<address>usa</address>
</person>
<person>
<fistname>micheal</firstname>
<lastname>jannet</lastname>
<address>usa</address>
</person>
</addressbook>

parse this xml using sax or dom parser and convert to java object(sample.java) and then convert the object to output.xml

please help me!!!

Thanks in advance,
Priya.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could parse the XML into a DOM tree and then do something like this:

Now, in the "processPersonElement" method, you can create an instance of foo.bar.Person, populate it's fields, put it into a collection of some sort, etc.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic