How can I covert a an xml file to a simple java bean? Its a simple xml file without any xsd, which was generated from a java bean, which I don't have access to.
I tried using xmlbeans to first generate the xmd from xml and then to generate classes from the xsd. I got a bunch of classes. I am looking for a single java bean class.
You could use a tool like Castor or JAXB to map the XML to a java class. Castor is fairly easy to use.
JAXB
JAXB (JSR-222) provides an easy way to convert objects to XML. There are many open source implementations of this standard including:
JAXB has a default mapping for Java objects to XML. This mapping can be customized through the application of annotations.
Would correspond to the following XML:
EclipseLink JAXB (MOXy)
MOXy has an XPath based mapping extension. This means we can take our same Address class and map it to Google's geocode format:
The above class corresponds to the following XML:
For more Information
Try Castor Mapping.