Simple java XML to POJO mapping / binding?

I tried to find the easiest way to map an XML file to a simple old Java object

Note: in my example, the XML does not match the POJO I want

///////// THE XML
<?xml version="1.0" encoding="UTF-8"?>
<Animal>
  <standardName>
    <Name>Cat</Name>
  </standardName>
  <standardVersion>
    <VersionIdentifier>V02.00</VersionIdentifier>
  </standardVersion>
</Animal>


////// THE INTENDED POJO
class Animal
{
 private String name;
 private String versionIdentifier;
}

JAXM element name annotation does not allow me to specify nested elements, so regular JAXB (Annotated) will not work (i.e. standardname / name)

I've seen jibx, but it seems too complex to provide a complete example of what I want to do

Castro seems to be able to do what I want (using mapping files), but I wonder if there are other possible solutions (it may make me skip the mapping file and only allow me to specify everything in the comments)

thank you

Solution

This article may help you... It just needs you to know XPath

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>