Content starts here Add a Complex Child Element to a Return Type
This page last changed on Mar 11, 2008.

eDocs Home > BEA AquaLogic Data Services Platform Documentation > Data Services Developer's Guide > Contents

How To Add a Complex Child Element to a Return Type

This topic describes how to add a complex child element to a return type, in Studio or in the XML source of the return type.

Add the Child Element Visually

Once you create a return type, you can add a complex type as a child of any element, in Query Map view. The complex child element must represent a physical data service. The parent element can have a one-to-many or one-to-one relationship with the child, depending on how you want the result data returned.

A Simple Return Type Before Adding a Child Element

To add a complex child element to a return type visually:

  1. Open the logical data service in Studio.
  2. Check Project Explorer. Be sure that your dataspace project has a physical data service for the complex child element you want to add. If it does not, add one

    File > New > Physical Data Service

  3. Click the Query Map tab.
  4. In the return type, right-click the new parent element, and choose Add Complex Child Element.
     

  5. For the Schema File field, browse (...) to the schema of the physical data service that represents the complex child element.
  6. For Type, choose a complex type from the schema, then click OK.
  7. From Project Explorer, drag the primary read function of the physical data service to the Query Map.
  8. Starting from the child element's For block, drag the zone icon to the child element in the return type. 
  9. Starting from the child element's For block, drag the parent type of the complex element to the return type.
    This step maps all of the elements in the complex child to the return type.
     

  10. Right-click the title bar of the return type, and choose Save and Associate XML Type.
  11. Click the Overview tab, and expand the schema to view the complex child in the return type.
    You can also right-click the schema and choose Edit Schema to view the XML source.
     

Edit the XML Source

Adding the complex child element to the return type in the XML source accomplishes the same thing as adding it visually.  

To add a complex child element to a return type in XML source:

  1. Open the logical data service in Studio.
  2. Check Project Explorer. Be sure that your dataspace project has a physical data service for the complex child element you want to add. If it does not, add it:
    File > New > Physical Data Service
  3. Click the Overview tab.
  4. Right-click the return type schema in the center, and choose Edit Schema.
    You see the schema for the logical data service, without the child element:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="ld:logical/MyCustomer" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="CUSTOMER">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="CUSTOMER_ID" type="xs:string"/>
            <xs:element name="FIRST_NAME" type="xs:string"/>
            <xs:element name="LAST_NAME" type="xs:string"/>
            <xs:element name="CUSTOMER_SINCE" type="xs:date"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
  5. In Project Explorer, right-click the schema file of the physical data service that represents the child element, and choose Open With.
    You see the schema of the child element.
  6. Copy the complex type from the physical data service schema to the logical data service schema. Take only the complex type:
    <xs:complexType>
             <xs:sequence>
                <xs:element name="ADDR_ID" type="xs:string"/>
                <xs:element name="CUSTOMER_ID" type="xs:string"/>
                <xs:element name="FIRST_NAME" type="xs:string"/>
                <xs:element name="LAST_NAME" type="xs:string"/>
                <xs:element name="STREET_ADDRESS1" type="xs:string"/>
                <xs:element name="STREET_ADDRESS2" type="xs:string" minOccurs="0"/>
                <xs:element name="CITY" type="xs:string"/>
                <xs:element name="STATE" type="xs:string"/>
                <xs:element name="ZIPCODE" type="xs:string"/>
                <xs:element name="COUNTRY" type="xs:string"/>
                <xs:element name="DAY_PHONE" type="xs:string" minOccurs="0"/>
                <xs:element name="EVE_PHONE" type="xs:string" minOccurs="0"/>
                <xs:element name="ALIAS" type="xs:string" minOccurs="0"/>
                <xs:element name="STATUS" type="xs:string" minOccurs="0"/>
                <xs:element name="IS_DEFAULT" type="xs:short"/>
             </xs:sequence>
     </xs:complexType>
  7. Right-click in the schema, and choose Validate.

See Also

How Tos
Other Resources
Document generated by Confluence on Apr 28, 2008 15:54