Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/DesignDocs/293925/MOXyExtensions/XMLDirectMapping
< EclipseLink | DesignDocs | 293925 | MOXyExtensions
XMLDirectMapping
Provide support for XML direct mappings via xml-element and xml-attribute.
The following table shows ...
Example: Configure an XMLDirectMapping via xml-element
The following example will demonstrate how to configure an XMLDirectMapping via xml-element:
Java Code
XMLDirectMapping idMapping = new XMLDirectMapping(); idMapping.setAttributeName("id"); idMapping.setXPath("@id"); XMLDirectMapping firstNameMapping = new XMLDirectMapping(); firstNameMapping.setAttributeName("firstName"); firstNameMapping.setXPath("first:name/text()"); XMLDirectMapping lastNameMapping = new XMLDirectMapping(); lastNameMapping.setAttributeName("lastName"); lastNameMapping.setXPath("last:name/text()"); NamespaceResolver namespaceResolver = new NamespaceResolver(); namespaceResolver.put("first", "myUri/first.xsd"); namespaceResolver.put("last", "myUri/last.xsd"); namespaceResolver.put("root", "myUri/root.xsd"); XMLDescriptor descriptor = new XMLDescriptor(); descriptor.setJavaClass(Employee.class); descriptor.setDefaultRootElement("root:employee"); descriptor.setNamespaceResolver(namespaceResolver); descriptor.addMapping(firstNameMapping); descriptor.addMapping(lastNameMapping); === XML Metadata === <source lang="xml"> <?xml version="1.0" encoding="US-ASCII"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> <java-types> <java-type name="org.example.Employee"> <java-attributes> <xml-element java-attribute="id" xml-path="id/text()"/> </java-attributes> </java-type> </java-types> </xml-bindings>