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

From Eclipsepedia

Jump to: navigation, search
(Mapping to Text Nodes with a Grouping Element)
(Mapping to Text Nodes with a Grouping Element)
Line 83: Line 83:
 
</source>
 
</source>
  
'''''XML Direct Collection Mapping to Text Nodes'''''
+
'''''XML Direct Collection Mapping to Text Nodes with a Grouping Element'''''
  
 
[[Image:dcge.png|XML Direct Collection Mapping to Text Nodes]]<br><br>
 
[[Image:dcge.png|XML Direct Collection Mapping to Text Nodes]]<br><br>
Line 89: Line 89:
 
The following example shows how to annotate your Java class to obtain this mapping with EclipseLink.  All that is needed is the standard JAXB <tt>@XmlElement</tt> annotation.
 
The following example shows how to annotate your Java class to obtain this mapping with EclipseLink.  All that is needed is the standard JAXB <tt>@XmlElement</tt> annotation.
  
'''''Java for XML Direct Collection Mapping to Text Nodes'''''
+
'''''Java for XML Direct Collection Mapping to Text Nodes with a Grouping Element'''''
 
<source lang="java">
 
<source lang="java">
 
@XmlRootElement
 
@XmlRootElement
Line 100: Line 100:
 
The example below shows how to to define your mapping information in EclipseLink's OXM metadata format.
 
The example below shows how to to define your mapping information in EclipseLink's OXM metadata format.
  
'''''OXM for XML Direct Collection Mapping to Text Nodes'''''
+
'''''OXM for XML Direct Collection Mapping to Text Nodes with a Grouping Element'''''
 
<source lang="xml">
 
<source lang="xml">
 
...
 
...

Revision as of 17:59, 20 December 2010


link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Contents

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

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

<?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:sequence>
         <xsd:element name="email-address" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
 
</xsd:schema>

XML Direct Collection Mapping to Text Nodes

XML Direct Collection Mapping to Text Nodes

The following example shows how to annotate your Java class to obtain this mapping with EclipseLink. All that is needed is the standard JAXB @XmlElement annotation.

Java for XML Direct Collection Mapping to Text Nodes

@XmlRootElement
public class Customer {
   @XmlElement(name="email-address")
   public List<String> emailAddress;
}

The example below shows how to to define your mapping information in EclipseLink's OXM metadata format.

OXM for XML Direct Collection Mapping to Text Nodes

...
<java-type name="Customer">
   <xml-root-element name="customer"/>
   <java-attributes>
      <xml-element java-attribute="emailAddresses" name="email-address"/>
   </java-attributes>
</java-type>
...

Mapping to Text Nodes with a Grouping Element

Given the XML schema in this example, the figure below illustrates an XML direct collection mapping to elements in a corresponding XML document, using a grouping element to contain the elements of the collection.

Schema for XML Direct Collection Mapping to Text Nodes with a Grouping Element

<?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:sequence>
         <xsd:element name="email-address" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
 
</xsd:schema>

XML Direct Collection Mapping to Text Nodes with a Grouping Element

XML Direct Collection Mapping to Text Nodes

The following example shows how to annotate your Java class to obtain this mapping with EclipseLink. All that is needed is the standard JAXB @XmlElement annotation.

Java for XML Direct Collection Mapping to Text Nodes with a Grouping Element

@XmlRootElement
public class Customer {
   @XmlElement(name="email-address")
   public List<String> emailAddress;
}

The example below shows how to to define your mapping information in EclipseLink's OXM metadata format.

OXM for XML Direct Collection Mapping to Text Nodes with a Grouping Element

...
<java-type name="Customer">
   <xml-root-element name="customer"/>
   <java-attributes>
      <xml-element java-attribute="emailAddresses" name="email-address"/>
   </java-attributes>
</java-type>
...