aspose file tools*
The moose likes XML and Related Technologies and the fly likes Simple Java to XML binding (NOT vice versa) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Simple Java to XML binding (NOT vice versa)" Watch "Simple Java to XML binding (NOT vice versa)" New topic
Author

Simple Java to XML binding (NOT vice versa)

Prash Negu
Ranch Hand

Joined: Apr 20, 2009
Posts: 45
Hi All,

I have simple requirement to convert a Java Bean to XML document (NOT other way). The intermediate mapping file should NOT be mandatory as the structure of bean is simple most of the time.

I was looking at Castor and JAXB (annoted beans). Is there any other simple tools do the same.

Thanks,
Prashant
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
java.beans.XMLEncoder comes to mind.


Ping & DNS - my free Android networking tools app
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I have simple requirement to convert a Java Bean to XML document (NOT other way).


The easiest way to create an XML-based document from data that is part of a Java object is to create a simple toXML() method. There really is no need for any binding framework or API. It really is very simple.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
I agree with Jimmy! By writing your own toXML method you have absolute control and it is bound to be much faster - take a look at the source code and all the antics that XMLEncoder gets up to.

It is also pretty simple to make a constructor that takes an Element.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Java to XML binding (NOT vice versa)