Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Simple Values/Collections/XMLDirectCollectionMapping"

(Mapping to Text Nodes)
m (Replacing page with 'Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values002.htm')
 
(40 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values002.htm
|info=y
+
|api=y
+
|apis= * [http://www.eclipse.org/eclipselink/api/latest/javax/xml/bind/annotation/XmlAttribute.html XmlAttribute]
+
* [http://www.eclipse.org/eclipselink/api/latest/javax/xml/bind/annotation/XmlElement.html XmlElement]
+
* [http://www.eclipse.org/eclipselink/api/latest/javax/xml/bind/annotation/XmlValue.html XmlValue]
+
|toc=y
+
}}
+
=XML Direct Collection Mappings=
+
XML direct collection mappings map a collection of simple Java values directly to XML text nodes. You can use an XML direct collection mapping in the following scenarios:
+
* [[#Mapping to Text Nodes|Mapping to Text Nodes]]
+
* [[#Mapping to Text Nodes with a Grouping Element|Mapping to Text Nodes with a Grouping Element]]
+
 
+
 
+
 
+
==Mapping to Text Nodes==
+
 
+
Given the XML schema in this example, the figure below illustrates an XML direct collection mapping to elements in a corresponding XML document.
+
 
+
'''''Schema for XML Direct Collection Mapping to Text Nodes'''''
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
 
+
  <xsd:element name="customer" type="customer-type"/>
+
 
+
  <xsd:complexType name="customer-type">
+
      <xsd:element name="email-address" type="xsd:string" maxOccurs="unbounded"/>
+
  </xsd:complexType>
+
 
+
</xsd:schema>
+
</source>
+
 
+
<span id="Figure 58-5"></span>
+
'''''XML Direct Mapping to an Attribute'''''
+
 
+
[[Image:dxmatt.gif|XML Direct Mapping to an Attribute]]<br><br>
+
 
+
The [[#Example 58-11|Java for XML Direct Mapping to an Attribute]] example shows how to annotate your Java class to obtain this mapping with EclipseLink.  All that is needed is the standard JAXB <tt>@XmlAttribute</tt> annotation.
+
 
+
<span id="Example 58-11"></span>
+
'''''Java for XML Direct Mapping to an Attribute'''''
+
<source lang="java">
+
@XmlRootElement
+
public class Customer {
+
  @XmlAttribute
+
  public Integer id;
+
}
+
</source>
+
 
+
The [[#Example 58-11-2|OXM for XML Direct Mapping to an Attribute]] example shows how to to define your mapping information in EclipseLink's OXM metadata format.
+
 
+
<span id="Example 58-11-2"></span>
+
'''''OXM for XML Direct Mapping to an Attribute'''''
+
<source lang="xml">
+
...
+
<java-type name="Customer">
+
  <xml-root-element name="customer"/>
+
  <java-attributes>
+
      <xml-attribute java-attribute="id"/>
+
  </java-attributes>
+
</java-type>
+
...
+
</source>
+
 
+
==Mapping to Text Nodes with a Grouping Element==
+

Latest revision as of 10:17, 8 November 2012

Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values002.htm