Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be 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/UserGuide/MOXy/Simple Values/Collections/XMLDirectCollectionMapping"

(Mapping to Text Nodes)
(Mapping to Text Nodes)
Line 22: Line 22:
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
+
 
   <xsd:element name="customer" type="customer-type"/>
 
   <xsd:element name="customer" type="customer-type"/>
 
+
 
   <xsd:complexType name="customer-type">
 
   <xsd:complexType name="customer-type">
       <xsd:element name="email-address" type="xsd:string" maxOccurs="unbounded"/>
+
       <xsd:sequence>
 +
        <xsd:element name="email-address" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
 +
      </xsd:sequence>
 
   </xsd:complexType>
 
   </xsd:complexType>
 
+
 
</xsd:schema>
 
</xsd:schema>
 
</source>
 
</source>

Revision as of 17:21, 20 December 2010


Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

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 Mapping to an Attribute

XML Direct Mapping to an Attribute

The 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 @XmlAttribute annotation.

Java for XML Direct Mapping to an Attribute

@XmlRootElement
public class Customer {
   @XmlAttribute
   public Integer id;
}

The OXM for XML Direct Mapping to an Attribute example shows how to to define your mapping information in EclipseLink's OXM metadata format.

OXM for XML Direct Mapping to an Attribute

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

Mapping to Text Nodes with a Grouping Element

Copyright © Eclipse Foundation, Inc. All Rights Reserved.