• 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

To create an xml from a java bean

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java class( a bean ) wih a number of properties. I need to create an xml file which is closely tied with the bean. How can I do it?
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend XMLBeans (Apache library free for use: http://xmlbeans.apache.org/).

It doesn't exactly solve your problem, but can be used to create an XSD (an XML file that defines an XML structure) that closely ties in with your class. The more common use though, is to take an XSD, generate java bean classes out of it, and then to use those beans to automatically create XML files out loaded data.

Once the Bean classes have been generated from an XSD, generating an XML file from data is a trivial process... you just load the data into these generated been classes using the factory methods, then output the data using save() to an output stream.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since we are starting from a Java class and not the xml, castor or Jibx may be better fits.
[ January 31, 2006: Message edited by: Rajagopal Manohar ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't that what the java.beans.XMLEncoder class is designed to do?

I need to create an xml file which is closely tied with the bean. How can I do it?


Bill
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used to use Castor, but it was just too heavy (size wise) to XStream (http://xstream.codehaus.org/) so I switched over. Works pretty good with little or no setup

 
reply
    Bookmark Topic Watch Topic
  • New Topic