XML mapping editor examples

The XML mapping editor is a visual data mapping tool that is designed to transform any combination of XML schema, DTD, or XML documents and produce a deployable transformation document. You can map XML-based documents graphically by connecting elements from a source document to elements of a target document. You can extend built-in transformation functions using custom XPath expressions and XSLT templates. The mapping tool automates XSL code generation and produces a transformation document based on the mapping information you provide.

Mapping transformation examples Description
Purchase order to shipping order map This example illustrates a business scenario in which two business units need to seamlessly exchange information. In this scenario, a purchase order document from the sales department is mapped to a shipping order document in the logistics department. The mapping consists of the following key transformations:
  • Move
  • Concatenation
  • Inline map
  • Substring
  • Group
  • Custom
Move This example demonstrates how the value of an element in the source document is moved to an element in the target document.
Concatenation This example demonstrates how the values from a set of items in the source document are concatenated into a single value of an item in the target document.
Inline map This example demonstrates how to create a map within a map to enable transformation of complex elements within their own context.
Substring This example demonstrates how to split the value of an element in the source document and copy the result to an element in the target document.
Group This example demonstrates how to group elements in the source document and store the result in the target document.
Custom This examples demonstrates how you can extend the built-in transform functions of the mapping tool using XPath expressions.

Purchase order to shipping order map

In this example, a purchase order document from the sales department must be processed by the logistics department to generate a shipping order document.
  1. To launch the XML Mapping wizard, select: File > New > Other > XML > XML Mapping. Click Next.
  2. In the File name field, type MyOrderMapping.map, and click Next.
  3. In the Root inputs pane, click Add.
  4. Select XML Schema from the Files of type drop-down list, and click Browse. Expand samples > PurchaseSample and select PurchaseOrder.xsd, and click OK.
  5. Choose PurchaseOrder as the source root element, and click OK.
  6. In the Root outputs pane, click Add.
  7. Select XML Schema from the Files of type drop-down list, and click Browse. Expand samples > PurchaseSample and select ShippingOrder.xsd, and click OK.
  8. Choose ShippingOrder as the target root element and click OK.
  9. Click Next.
  10. To select a sample XML input file, click Add. Choose PurchaseOrder.xml and click OK.
    Note: Use a sample XML input file to test your mapping transformations.
  11. Click Finish.

Move

In this example, the value of the OrderID element in the PurchaseOrder document is moved to value of the PurchaseOrderReference attribute in the ShippingOrder document.
  • In the XML mapping editor, click the OrderID element from PurchaseOrder and drag it to the PurchaseOrderReference attribute in ShippingOrder.
Move transform

Concatenation

In this example the first, middle, and last name elements of the PurhchaseOrder document are concatenated into a single value for the CustomerName element in the ShippingOrder document.
  1. In the XML mapping editor, click the FirstName element from PurchaseOrder and drag it to the CustomerName element in ShippingOrder.
  2. Click the LastName element from PurchaseOrder and drag it to the transform type box between PurchaseOrder and ShippingOrder.
    Note: After you drag a second element to the transform type box, the transform type should automatically change to Concat.
  3. Click the MiddleInitial element from PurchaseOrder and drag it to the transform type box.Concatenation transform
  4. Right-click the transform type box, and select Show in Properties.
  5. To change the order of concatenation values, click the Order tab in the Properties view. Click MiddleInitial, and click the up arrow Reorder icon.
    Note: You can customize concatenation options for ordering, delimiters, prefix, and postfix.

Inline map

In this example both source and target documents contain the complex element ShippingAddress.

  1. In the XML mapping editor, click the ShippingAddress element from PurchaseOrder and drag it to the ShippingAddress element in ShippingOrder.Inline map transform
  2. Click the edit icon at the top right corner of the transform type box.
    Note: You must map each ShippingAddress sub-element in the Inline map details view.
  3. In the Inline map details view, perform the following mapping transforms:
    1. Click the StreetNumber element and drag it to the StreetAddress element.
    2. Click the StreetName element and drag it to the transform type box. Repeat this for the Apartment element.
    3. Click the PostalCode element and drag it to the PostalCode element on the right.
    4. Click the Province element and drag it to the Province element on the right.Inline map details
  4. To return to the main map, click the arrow icon at the top right of the inline map details page.

Substring

In this example, the OrderDate element is stored as a single date type in the purchase order document, but in the shipping order document the same OrderDate element is separated into the sub-elements of year, month, and day integer types. By setting the appropriate substring transform parameters you can extract the year, month, and day values from the purchase order OrderDate element and store the values in the corresponding elements in the shipping order.

  1. Click the OrderDate element from PurchaseOrder and drag it to the Year element in ShippingOrder.
    1. Click the drop-down arrow in the transform type box, and select Substring from the list.
    2. Right-click the transform type box, and select Show in Properties.
    3. In the Properties view, in the Delimiter field, type -.
    4. In the Substring index field, type 0.
  2. Click the OrderDate element and drag it to the Month element.
    1. Change the transform type to Substring.
    2. In the Properties view, in the Delimiter field, type -.
    3. In the Substring index field, type 1.
  3. Click the OrderDate element and drag it to the Day element.
    1. Change the transform type to Substring.
    2. In the Properties view, in the Delimiter field, type -.
    3. In the Substring index field, type 2.
Substring transform
Note: You can apply the substring transforms or concatenation transforms to elements and attributes of any type, not just string types.

Group

In this example, each product in the purchase order has an associated shipping priority while in the shipping order, products are grouped by shipping priority section elements. Using the group transform you can group products in the purchase order by their shipping priority and map the resulting group to an element in the shipping order. In the group properties, you can set the grouping parameters and the order and sort criteria.
  1. Click the Product element from PurhaseOrder and drag it to the OrderSection element in ShippingOrder
  2. Click the transform type box and select Group.Group transform
    1. Right-click the transform type box, and click Show in Properties.
    2. In the Properties view, click ShippingPriority in the left pane.
    3. Click Add.
  3. To view group details, click the arrow at the top right of the transform type box.
  4. In the group details view, perform the following move operations:
    1. Move the ID element to the Identifier element.
    2. Move the Price element to the Price element on the right.
    3. Move the Description element to the Name element.
    4. Move the Quantity element to the Quantity element on the right.
    5. Move the ShippingPriority element to the Priority element.
  5. To return to the man map view, click the arrow at the top right of the group details page.

Custom

In this example, the shipping order document contains a NumberOfProducts attribute to specify the total number of products in the order. To generate the value for the NumberOfProducts attribute, the sum total of the products from the purchase order must be calculated using the quantity element. You can use an XPath expression to perform the addition operation using a custom transformation. The result is then stored in the target attribute, NumberOfProducts.
  1. Click the PurchaseOrder element and drag it to the NumberOfProducts element in ShippingOrder.
  2. Click the transform type box, and select Custom.Custom transform
  3. Right-click the transform type box, and select Show in Properties.
  4. In the Properties view, you can create an XPath expression. For this example, type sum(Product/Quantity).Custom transform property sheet
Parent topic: Mapping XML documents

Feedback