Our Java application receives XML messages from a number of external systems and from these we want to create domain objects. We do not have schemas for these documents.
Currently we are are using XPaths to pull out strings from the XML and then calling setters on the new domain object. We use a home-baked XmlUtils class to do this.
foo.setBar(XmlUtils.number("/bar", document));
What alternative Java-based approaches are there, which do not require access to the document’s schema?
Note: I’m the EclipseLink JAXB (MOXy) lead, and a member of the JAXB 2.X (JSR-222) expert group.
MOXy offers the
@XmlPathextension which enables you to do XPath based mapping:Path Based Mapping
Match the
barelement under thefooelement:Position Based Mapping
Match the second
barelement:Predicate Based Mapping
Match the
barelement that has atypeattribute with valuefoo:Combined
All of the above concepts can be used together:
For More Information