Simple Java Xml to POJO mapping/binding?

后端 未结 4 1864
一向
一向 2020-12-10 05:41

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

4条回答
  •  情歌与酒
    2020-12-10 05:56

    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:

    • http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
    • http://bdoughan.blogspot.com/2010/07/xpath-based-mapping.html
    • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/MOXyExtensions

    EclipseLink also allows the metadata to be specified using an external configuration file:

    • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/ExternalizedMetadata

提交回复
热议问题