Combining Data From Different Schemas

You can use the mapper functionality to combine the contents of two different schemas, as shown in the following figure:

Figure : Combining Data From Different Schemas

image

In this case, the customer information is merged with the line-items repeating element to form one combined XML document.

This example describes how to create a transformation which combines the data from two different XML Schemas. This example shows how to combine the XML sample data shown in the preceding figure. In this example, the source data is not constrained or limited to produce the target data—a where clause was not added to the for loop iterating over the purchase-order/line-items/line-items using the Constraints tab.

To Combine Data From Different Schemas

  1. Import the two XSD files that contain the XML Schemas for the source types of the transformation. For instructions, see Selecting Source and Target Types.
  2. For this example, import the files: CustInfo.xsd and PO.xsd files. If you installed WebLogic Platform in the c:\bea directory, import these files from the c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\dataDiffSchemas directory.

    Note: The PO.xsd file used in this example is identical to the PO.xsd file used in Using the Union Option of the Constraints Tab. If you have already imported the PO.xsd file for the Using the Union Option of the Constraints Tab example, you do not need to import it again.

  3. Import the XSD file that contains the XML Schema for the target type of the transformation. For instructions, see Selecting Source and Target Types.
  4. For this example, import the file: POCustInfo.xsd. If you installed WebLogic Platform in the c:\bea directory, import this file from the c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\dataDiffSchemas directory.

    Importing schemas files triggers a build of the current Schemas project folder. Wait until the current Schemas project folder is built before proceeding to the next step. (The representations of the schemas will not be available in Available Source Types and Available Target Type panes until build is complete.)

  5. Create a Transformation file and a method in the Transformation file. For instructions, see Creating a Transformation File and a Transformation Method.
  6. Select the Transformation method from a Transformation file.
  7. To select an existing method, in the Design View of the Transformation file:

    1. Right-click the arrow representing the method.
    2. From the drop-down menu, select Configure XQuery Transformation Method.
  8. Select the source types for the transformation:
    1. In the Available Source Types pane, expand the schema and element folders, until you find the desired element.
    2. In the Available Source Types pane, select the desired element.
    3. Click Add.

    The elements and attributes that make up the selected element are displayed in the Selected Source Types pane.

    For this example, select and add the CustInfo.xsd/customer and PO.xsd/purchase-order nodes.

  9. Select the target type for the transformation:
    1. In the Available Target Types pane, expand the schema and element folders, until you find the desired element.
    2. For this example, expand the POCustInfo.xsd schema folder.

    3. In the Available Source Types pane, select the desired element.
    4. For this example, select the POCustInfo.xsd/purchase-order element.

    5. Click Add.
    6. The elements and attributes that make up the selected element are displayed in the Selected Target Types pane.

  10. Click Create Transformation.
  11. The Design View of the XQ file is displayed.

  12. Create links between repeating element nodes:
    1. In the Source pane, select the repeating element and drag it to the repeating element in the Target pane.
    2. For this example, link the $purchase_orderDoc/line-items/line-item repeating element to the purchase-order/line-items/line-item repeating element.

      A dashed line linking the two repeating elements is displayed. The dashed line with short dashes represents a structural link—a link between two parent structures that does not map data directly. The dashed-line representation for a structural link is shown in the following figure:

      image

      To learn more about links, see Link Representations.

    3. In the Source pane, select each of the subelements of the repeating element and drag them to the analogous subelement of the repeating element in the Target pane.
    4. For this example, link the $purchase_orderDoc/line-items/line-item/part-no element to the purchase-order/line-items/line-item/part-no element. In addition, link the $purchase_orderDoc/line-items/line-item/quantity element to the purchase-order/line-items/line-item/quantity element.

      Two solid lines linking the two subelements is displayed. These solid lines represents a data link—a link that converts the value of the source node directly to the value of the target node The solid line representation for a data link is shown in the following figure.

      image

      To learn more about links, see Link Representations.

  13. Create links between the second set of nodes:
    1. In the Source pane, select the $customerDoc node and drag it to the $purchase-order/customer node in the Target pane. A structural link between the two nodes is created.
    2. Right-click the structural link between the $customerDoc node and the $purchase-order/customer node and from the pull-down menu select Induce Map.
    3. A data link between the $customerDoc/customer-id node and the $purchase-order/customer/customer-id node is created.

      A data link between the $customerDoc/customer-name node and the $purchase-order/customer/customer-name node is created.

      A data link between the $customerDoc/customer-address node and the $purchase-order/customer/customer-address node is created.

      The map between the source and target elements is shown in the following figure.

      image

  14. Select the Test View tab.
  15. Import XML or non-XML files as source data for the transformation. For more information, see Creating Maps.
  16. For this example, in the Source Data pane, select the $purchase_orderDoc node and import the file: InputPO.xml. In the Source Data pane, select the $customerDoc node and import the file: InputCust.xml. If you installed WebLogic Platform in the c:\bea directory, import these files from the c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\dataDiffSchemas\XML directory.

    Note: You can cut and past directory paths into the Name field of the Open File to Test pane to jump to directory locations. If you installed WebLogic Platform in the c:\bea directory, you can jump to the directory that contains the XML files for this example, by pasting the following directory path into the Name field: c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\dataDiffSchemas\XML and then pressing enter.

  17. In the Result Data pane, click Test.
  18. If not currently running, the WebLogic Server for the current application will be started. In order for a query to run, the WebLogic Server for the current application must be running.

    In the Result Data pane, after the query is run a graphical representation of the target data is displayed.

  19. If the target data is XML data, in the Result Data pane, you can view the resulting data as an XML document by selecting the XML Source View tab. The XML result for this example is also displayed in Figure: Combining Data From Different Schemas.
  20. If desired, you can validate the result data against the associated schema. In the Result Data pane of the Test View, click Validate. To learn more, see Validating During Design Time.
  21. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.
Previous Document Next Document