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

Simple Java to XML binding (NOT vice versa)

 
Prash Negu
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.beans.XMLEncoder comes to mind.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic