This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Converting Xml to Java Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting Xml to Java Object" Watch "Converting Xml to Java Object" New topic
Author

Converting Xml to Java Object

prakash pawar
Ranch Hand

Joined: Mar 11, 2010
Posts: 42
Hi All,

I have requirement where we are getting an Xml file and want that data in java Object.
what is the best way i can do it ?

Thanks in advance.


Regards,
Prakash Pawar.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Apache Commons Digester is a powerful library for this if you only need the XML-->Java direction. If you need both directions, then the JAXB API can help.


Ping & DNS - updated with new look and Ping home screen widget
Kannan Sekar
Greenhorn

Joined: May 09, 2008
Posts: 1
Hi,

You can even try Apache's XmlBeans which easily converts the xml in to java objects.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Welcome to the Ranch Kannan Sekar
Emil dombagolla
Greenhorn

Joined: May 26, 2010
Posts: 3
Use can use jaxb

K Sekar
Greenhorn

Joined: Sep 08, 2006
Posts: 8
Thank you Campbell Ritchie.
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
You can use JAXB to read xml and set values in java object. For using jaxb , you need to create xsd files.

There are multiple sites which will tell you how to create xsd files.
Ashish P Gandhi
Greenhorn

Joined: May 25, 2010
Posts: 2
Actually depends on how complex your xml is....if its very simple xml, then you can just parse the xml and create your object.
If its complex, then JAXb would be a better option, for creating an xsd, there are tools available which make it simpler ( Altova's XMLSpy is a good option for free trial)


Regards,
Ashish Gandhi
SCJP 6.0, SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting Xml to Java Object
 
Similar Threads
question about xstream
Java to XML
XML file generation
object to XML
how to get XML from javaobject using JAXB