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

object to XML

 
carlos Muller
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Forum, I need to convert a object to XML, I find a "function" (Imagine that is not so simple) like:

class Cone{
String radius = "0.2";
String bottom = "true";
}

-> public String function??(Class Cone, Object obj) ->

<Cone>
<radius>0.2</radius>
<bottom>true</bottom>
</Cone>

I think the packages javax.xml.* can help me, but I don't see How. Somebody Knows Where can I find information of this?

Thanks.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for JAXB.
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlos,
This question has nothing to do with Webservices forum, so I am moving this to XML and Related Technologies forum.
Please continue your discussion there.
Thank you.
Balaji
 
Chetya Benkipuri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a look at jibx as well
http://jibx.sourceforge.net/

or XmlBeans at
http://xmlbeans.apache.org/

Personally,I feel jibx is better.
The site is easy to understand.XmlBeans tutorials are buggy or atleast they don't work as the ppl say.

Hope this helps.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can you please help me to select an XML to java Object and vice versa framework ?
I need it to be fast in converting an XML file to a java Object and vice versa.


Thanks
 
Kim Visser
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAXB might be your guess ..
but there are others, have a look here:

Bindmark @ dev.java.net
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, my choice would be to give your Java object a outputToXML( PrintStream ) method and a constructor that takes an XML Element and extracts the data it needs.
This is guaranteed to be faster than any other approach.
Bill
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
give your Java object a outputToXML( PrintStream ) method and a constructor that takes an XML Element and extracts the data it needs.


While not essential, StAX's input and output API can be useful with that type of an approach - though it will require some additional JAR's.
An Introduction to StAX
JSR 173: Streaming API for XML
Sun's API and implementation JARs for StAX can be found in the JWSDP 1.6 for StAX 1 and in JWSDP 2.0 for StAX 2.0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic