• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Object to XML  RSS feed

 
JPraveen Kumar
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there any direct way to save a Java object as XML like
class a {int b = 10;}
to <a><b>10</b></a> without having to field by field iterate and create DOM nodes etc.
Can Serialize help me to achieve this?

Tx Praveen.
 
Julien Grenier
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the XMLEncoder and XMLDecoder class.

I've been playing around these two classes a long time ago and they were working pretty well.

Julien Grenier
p.s: if you need an example I could post one but you might want to check my your self.
 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes there is an easier method to save the object as XML. There is an freely available API called XStream which will do this for you very easily.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a more powerful (and correspondingly more involved) approach, have a look at the JAXB API.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks for the heads up.

How does xstream compare to say Castor. I noticed it doesn't use a mapping file. I need to save classes to XML, but not all properties. Just a few that need to be persisted. Can you do that with xstream.
 
JigaR Parekh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
castor is xml binding framefork. actually any xml binding framework will solve your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!