This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes To create an xml from a java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "To create an xml from a java bean" Watch "To create an xml from a java bean" New topic
Author

To create an xml from a java bean

dina raj
Greenhorn

Joined: Dec 06, 2005
Posts: 17
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
Rajagopal Manohar
Ranch Hand

Joined: Nov 26, 2004
Posts: 183
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Feb 08, 2005
Posts: 362
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To create an xml from a java bean
 
Similar Threads
Two TransactionTemplate use my single application.
Generalized Parsing for SOAP Response
Simple Java to XML binding (NOT vice versa)
how to create Xml file programmatically
xml as database for java