• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic