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

constructing xml through java bean

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I have java bean in session, please, let me kow how can i construct a xml file with ben properties and values as xml nodes.
which is the best approach to take.
i have to do it in jsp or in a class.
provide me details.

Thanks & Regards
srinivas reddy
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srinivas,
You want to do this in a Java class, not in the JSP. That would be way too much logic in a JSP.

It's just a matter of writing a method on the java bean that writes out XML. You need to decide on what the XML should look like. What should be the node names, etc.

If you are just doing this once, it is easiest to hand code. If you are doing it a lot, there are Java/XML mapping libraries that can generate the XML.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have something to add.
If there is no requirement to xml structure and the main idea - convert bean to xml and back populate to bean, then the XStream is very usable. Refer this two minutes tutorial
May be that is the best choice in your situation.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the beans truely conform to the JavaBeans spec, then the easiest would be to use the java.beans.XMLEncoder/XMLDecoder classes. No extra library to use and learn - very handy!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic