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.
Local 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 > Data Map. Click Next.
  2. In the New Data Mapping File Window, click the folder XMLMappingExamples. In the File name field, type MyOrderMapping.map, and then click Next.
  3. Beside the Root inputs pane, click Add.
  4. In the Files of type list, select XML Schema and then click Browse. Expand XMLMappingExamples, select PurchaseOrder.xsd, and click OK.
  5. In the Global Elements and Types pane, click PurchaseOrder as the source root element, and click OK.
  6. Beside the Root outputs pane, click Add.
  7. In the Files of type list, select XML Schema, and click Browse. Expand XMLMappingExamples, select ShippingOrder.xsd, and click OK.
  8. In the Global Elements and Types pane, click ShippingOrder as the target root element and click OK.
  9. Click Next.
  10. Beside the Data sample inputs for testing pane, click Add. Click 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 the value of the PurchaseOrderReference attribute in the ShippingOrder document.
  • If not already open, right-click MyOrderMapping.map and click Open. The mapping editor opens.
  • In the mapping editor, click the element OrderID 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 PurchaseOrder document are concatenated into a single value for the CustomerName element in the ShippingOrder document.
  1. In PurchaseOrder, expand the Customer element.
  2. In PurchaseOrder, click the FirstName element and drag it to the CustomerName element in ShippingOrder.
  3. Add the LastName element:
    1. In PurchaseOrder, click the LastName element and drag it to the Move transform type box between PurchaseOrder and ShippingOrder. The Connection Selection Helper window opens.
    2. In the Connection Selection Helper window, click Primary Connection.
  4. Add the MiddleInitial element:
    1. In PurchaseOrder, click the MiddleInitial element and drag it to the Concat transform type box between PurchaseOrder and ShippingOrder. The Connection Selection Helper window opens.
    2. In the Connection Selection Helper window, click Primary Connection. The window closes and the transform type changes to Concat.
    Concatenation transform
  5. Right-click the Concat box, and click Show In > Properties View.
  6. In the Properties view, click the Order tab. In the Inputs pane, click in the Properties view. Click MiddleInitial: string and then click the up arrow Reorder icon to change the order of the concatenated strings.
    Tip: You can customize concatenation options for ordering, delimiters, prefix, and postfix.
    Concatenation transform with order changed

Local map

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

  1. In PurchaseOrder, expand the ShippingInfo element.
  2. In PurchaseOrder, click the ShippingAddress element and drag it to the ShippingAddress element in ShippingOrder.Local map transform
  3. Edit the Local map by clicking the link in the information window that opens, or by clicking the edit icon which is in the upper-right corner of the Local Map transform type box. The editor opens for the local map.
  4. You must map transforms for each ShippingAddress sub-element:
    1. Map the StreetNumber, StreetAddress and Apartment elements in PurchaseOrder to the StreetAddress element in ShippingOrder:
      1. Click the StreetNumber element and drag it to the StreetAddress element.
      2. Click the StreetName element and drag it to the Move transform type box. The Connection Selection Helper window opens.
      3. In the Connection Selection Helper window, click Primary Connection. The window closes and the transform type changes to Concat.
      4. Click the Apartment element and drag it to the Concat transform type box. The Connection Selection Helper window opens.
      5. In the Connection Selection Helper window, click Primary Connection.
    2. Click the PostalCode element in PurchaseOrder and drag it to the PostalCode element in ShippingOrder
    3. Click the Province element in PurchaseOrder and drag it to the Province element in ShippingOrder.Local map details
  5. To return to the main map, click the arrow icon at the upper-right corner of the local map view.

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. In ShippingOrder, expand the OrderDate element.
  2. In PurchaseOrder, click the OrderDate element and drag it to the Year element in ShippingOrder.
    1. Click the drop-down arrow in the transform type box. Expand String Functions and then click Substring.
    2. Right-click the Substring transform type box, and then click Show In > Properties View.
    3. In the Properties view, click the General tab.
    4. In the in the Delimiter field, type -.
    5. In the Substring index field, type 0.
  3. In the mapping editor, click the OrderDate element and drag it to the Month element.
    1. Click the drop-down arrow in the transform type box. Expand String Functions and then click Substring.
    2. In the Properties view, click the General tab.
    3. In the Delimiter field, type -.
    4. In the Substring index field, type 1.
  4. In the mapping editor, click the OrderDate element and drag it to the Day element.
    1. Click the drop-down arrow in the transform type box. Expand String Functions and then click Substring.
    2. In the Properties view, click the General tab.
    3. In the Delimiter field, type -.
    4. In the Substring index field, type 2.
Substring transform
Tip: 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. In ShippingOrder, expand the OrderSections element.
  2. In PurchaseOrder, click the Product element and drag it to the OrderSection element in ShippingOrder
  3. Click the drop-down arrow in the transform type box and click Group in the Core Transforms section. Group transform
    1. Right-click the Group transform type box, and then click Show In > Properties View.
    2. In the Properties view, click ShippingPriority : String in the Product pane.
    3. Click Add.
  4. In the mapping editor, edit the Group details by clicking the edit icon that is in the upper-right corner of the Group transform type box. The editor opens for the OrderSection element.
  5. In the OrderSection details view, expand the OrderItem element.
  6. In the Group details view, perform the following move operations:
    1. Click the ID element in the Product and drag it to the Identifier element in the OrderSection.
    2. Click the Price element in the Product and drag it to the Price element in the OrderSection.
    3. Click the Description element in the Product and drag it to the Name element in the OrderSection.
    4. Click the Quantity element in the Product and drag it to the Quantity element in the OrderSection.
    5. Click the ShippingPriority element in the Product and drag it to the Priority element in the OrderSection.
    Group details mappings
  7. To return to the man map view, click the arrow at the upper-right of the group mapping.

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. The transform type is set to Custom XPath. Custom XPath transform
  2. Right-click the Custom XPath transform type box, and then click Show In > Properties View.
  3. In the Properties view, click the General tab and then click Edit.
  4. In the XPath Expression Builder window, type sum(Product/Quantity) and then click OK. Custom XPath transform property

Feedback