I\'m trying to figure out the simplest way to map an xml file to to a plain old java object.
Note: That in my example the xml doesn\'t quite match up with my intend
I consider JiBX the best of the bunch (JAXB, Castor, XMLBeans, etc.), particularly because I favor mapping files over annotations. Admittedly it has a decent learning curve, but the website has a lot of good examples. You must have missed the tutorial.
If you are only going one way (XML --> POJO) you could use Digester.
Side comment: I prefer mapping files over annotations because annotations:
This article may help you... it only requires you to know xpath http://onjava.com/onjava/2007/09/07/schema-less-java-xml-data-binding-with-vtd-xml.html
EclipseLink JAXB (MOXy) allows you to do the path based mapping that you are looking for:
@XmlRootElement
class Animal
{
@XmlPath("standardName/Name/text()")
private String name;
@XmlPath("standardVersion/VersionIdentifier/text()");
private String versionIdentifier;
}
For more information see:
EclipseLink also allows the metadata to be specified using an external configuration file:
Jakarta Commons Digester should do what you want.
Alternatively, I would recommend writing a transformation class that uses XPath to retrieve elements from the XML.