File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML to JAVA binding with CASTOR or JAXB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML to JAVA binding with CASTOR or JAXB" Watch "XML to JAVA binding with CASTOR or JAXB" New topic

XML to JAVA binding with CASTOR or JAXB

Kedlu Nanu

Joined: May 05, 2004
Posts: 6
Hello everybody,

I've XML file which is very Hierarchical in structure and I was wondering can I use castor or jaxb for generating java classes. I tried to use Castor sourcegenerator but it created too many java files for XML file. I guess it created java file for all elements and attributes. My XML file looks like this:

and much more embeded structure. I guess I can not use the form of <ad value=" "/> for castor?

Please suggest me the simplest way of mapping XML to JAVA classes.

[ February 11, 2005: Message edited by: Kedlu Nanu ]
Kedlu Nanu

Joined: May 05, 2004
Posts: 6
For any element if CASTOR/JAXB are creating classes then I can't afford that or am I doing something wrong?

Please comment
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
But what do you want actually?
Castor or any other JAXB Implementator SHOULD create those helper classes. otherwise how will you fill in the data in the actual Java Objects?

What I could recommend to you is actually that You should investigate the requirements of the functionality and go on later even without JAXB.
-If the data structure is too complicated in the XSD, I find that Castor's Mappings are not 100% correct.
-Do you have to process each element you receive as XML, or just some few of them, in this case I advice you to use the simplest API ever created for XML Processing: the SAX.

I agree. Here's the link:
subject: XML to JAVA binding with CASTOR or JAXB
Similar Threads
how to retrieve attribute value of a node
Resolving includes in XML
Help parse using JAXP
parsing XML files with SAX
XSLT - is it possible?