File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes object to XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "object to XML" Watch "object to XML" New topic
Author

object to XML

carlos Muller
Greenhorn

Joined: Apr 20, 2006
Posts: 14
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

Joined: Feb 27, 2002
Posts: 8898

Check for JAXB.


Groovy
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
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


Spritle Software Blogs
Chetya Benkipuri
Greenhorn

Joined: Apr 20, 2006
Posts: 5
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

Joined: Jul 14, 2005
Posts: 550
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

Joined: Apr 24, 2006
Posts: 1
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

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


Java Resources at www.wbrogden.com
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
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.


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: object to XML
 
Similar Threads
Arrays Sorting
Doubts in Writing TLD
Stopping Animation
How to refresh JPanel automatically when internal state changed?
stuck up in the problem