Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "EclipseLink/DesignDocs/293925/MOXyExtensions/XMLDirectMapping"

(XML Metadata)
Line 4: Line 4:
 
Provide support for XML direct mappings via xml-element and xml-attribute.
 
Provide support for XML direct mappings via xml-element and xml-attribute.
  
== XML Metadata ==
+
== Example: Configure an XMLDirectMapping via xml-element ==
  
The following table outlines how an xml-element can be declared to define an XMLDirectMapping:  
+
The following example will demonstrate how to configure an XMLDirectMapping via xml-element:
  
{|{{BMTableStyle}}
+
=== org.example.Employee.java ===
|-{{BMTHStyle}}
+
 
! XML Metadata
+
<source lang="java">
! Mapping
+
package org.example;
|-
+
 
| name
+
public class Employee {
| attributeName
+
    private int id;
|-
+
   
| xml-path
+
    public Employee() {
| XPath
+
    }
|}
+
 
 +
    public int getId() {
 +
        return id;
 +
    }
 +
 
 +
    public void setId(int newId) {
 +
        id = newId;
 +
    }
 +
}
 +
</source>
 +
 
 +
=== Code ===
 +
 
 +
<source lang="java">
 +
    XMLDirectMapping idMapping = new XMLDirectMapping();
 +
    idMapping.setAttributeName("id");
 +
    idMapping.setXPath("id/text()");
 +
</source>
 +
 
 +
=== xml-element ===
 +
 
 +
<?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>

Revision as of 11:19, 2 February 2010

XMLDirectMapping

Provide support for XML direct mappings via xml-element and xml-attribute.

Example: Configure an XMLDirectMapping via xml-element

The following example will demonstrate how to configure an XMLDirectMapping via xml-element:

org.example.Employee.java

package org.example;
 
public class Employee {
    private int id;
 
    public Employee() {
    }
 
    public int getId() {
        return id;
    }
 
    public void setId(int newId) {
        id = newId;
    }
}

Code

    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("id/text()");

xml-element

<?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>

Back to the top