aspose file tools*
The moose likes Beginning Java and the fly likes without xml schema, generate java classes from xml data file ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "without xml schema, generate java classes from xml data file ?" Watch "without xml schema, generate java classes from xml data file ?" New topic
Author

without xml schema, generate java classes from xml data file ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
without xml schema, is it possible generate java classes from xml data file ? using which library ?

Thanks.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

An XML file can be converted into a class hierarchy using JAXB but am not sure if a schema definition is mandatory for the operation. In case there is a dependency on XSD for this operation you can approach the same using JAXP parsers and POJOs. You will have to have the code which uses SAX/DOM parser APIs, iterate through the elements and set the values for the properties in the hierarchy.

I you were to give more details on what you are trying to accomplish, I might be able to suggest further options available.

Cheers,
Raj.
Sateesh.B Kumar
Greenhorn

Joined: Sep 05, 2007
Posts: 6
Raj Kamal wrote:
An XML file can be converted into a class hierarchy using JAXB but am not sure if a schema definition is mandatory for the operation.


To work with JAXB one needs to have a schema. I don't think using JAXB one can generate classes from an XML document alone.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

You can use XStream without XML schema file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: without xml schema, generate java classes from xml data file ?