Note: That in my example the xml doesn't quite match up with my intended POJO.
///////// THE XML
xml version="1.0" encoding="UTF-8"?>
<Animal>
<Name>Cat</Name>
</standardName>
<VersionIdentifier>V02.00</VersionIdentifier>
</standardVersion>
</Animal>
////// THE INTENDED POJO
class Animal
{
private String name;
private String versionIdentifier;
}
Regular JAXB (with annotations) won't work as the JAXM Element name
annotations don't allow me to specifiy nested elements. (i.e.
standardName/Name).I've looked at Jibx but it seems overly complicated, and no full examples are provided for what I want to do.
Castro seems like it would be able to do what I want (using mapping files), but I wonder if there are any other possible solutions. (Possibly that would allow me to skip mapping files, and just allow me to specify everything in annotations).
As an additional note, the mapping/binding would have to work both ways.
===
Ans)
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. |
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:
If you are only going one way (XML --> POJO) you could use Digester.
Side comment: I prefer mapping files over annotations because annotations:
- clutter the code (especially when using annotations from several products)
- mix concerns (XML, database, etc. in domain layer)
- can only bind to a single XML (or database, or web service, etc.) representation
EclipseLink JAXB (MOXy) allows you to do the path based mapping that you are looking for:
For more information see:
|
1 comment:
nice to learn.
Post a Comment