Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To create an xml from a java bean

 
dina raj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • 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.
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • 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 ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • 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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic