Skip Headers

# Specifying the Content Type of a Collection With an XML Composite Direct Collection Mapping

Previous

Next

By default, TopLink will treat the node values read by a composite direct collection XML mapping as objects of type `String`. You can override this behavior by specifying the type of the collection's contents.

Given the XML schema in Example: Schema for XML Composite Direct Collection Mapping with Specified Content Type, Figure: XML Composite Direct Collection Mapping with Specified Content Type illustrates an XML composite direct collection mapping to a simple sequence in a corresponding XML document. The mapping is configured to specify the content type of the collection as `Calendar`. Example: Java for XML Composite Direct Collection Mapping with Specified Content Type shows how to configure this mapping in Java.

Schema for XML Composite Direct Collection Mapping with Specified Content Type

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="employee" type="employee-type"/>
        <xsd:complexType name="employee-type">
            <xsd:sequence>
                <xsd:element name="vacation" type="xsd:string" maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

XML Composite Direct Collection Mapping with Specified Content Type

Description of "XML Composite Direct Collection Mapping with Specified Content Type"

Java for XML Composite Direct Collection Mapping with Specified Content Type

    XMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping();
    tasksMapping.setAttributeName("vacationDays");
    tasksMapping.setXPath("vacation/text()");
    tasksMapping.setAttributeElementClass(Calendar.class);