Skip to main content

Learn about XML data mapping

This guide provides a comprehensive overview of XML data mapping, a fundamental process for legacy system integration and data management. You will learn what XML is, what data mapping entails, and how to apply these concepts to transform data effectively.

What is XML?

XML (eXtensible Markup Language) is a text-based format for representing structured information. Unlike JSON, which uses key-value pairs, XML uses tags to define elements and attributes. It is widely used for data interchange, configuration files, and documents.

XML is built on a hierarchical, tree-like structure:

  • Elements: The primary building blocks, defined by start and end tags (e.g., <customer>...</customer>). Elements can contain text, other elements, or be empty.

  • Attributes: Provide additional information about an element and are included within the start tag (e.g., <order id="12345">).

<order id="12345">
<customer>
<firstName>John</firstName>
<lastName>Doe</lastName>
</customer>
<items>
<item>
<productId>A-456</productId>
<quantity>2</quantity>
</item>
<item>
<productId>B-789</productId>
<quantity>1</quantity>
</item>
</items>
<isShipped>false</isShipped>
</order>

What is data mapping?

Data mapping is the process of creating relationships between data fields from a source format to a target format. Think of it as creating a "map" that tells data from one system how to find its correct place in another system.

In the context of XML, it means transforming an input XML structure into a different output XML structure. This is crucial when two systems need to communicate but use different data schemas.

Why is XML data mapping essential?

Data mapping is the engine behind seamless system integration. Its primary purposes are:

  • System Integration: When connecting two different applications (e.g., a CRM and an e-commerce platform), their APIs will almost certainly use different XML structures. Mapping is required to translate the data so both systems can understand it.

  • Data Transformation: It’s not just about moving data. Mapping allows you to clean, enrich, restructure, and standardize data as it flows from one point to another. For example, you could combine a <firstName> and <lastName> from a source into a single <fullName> element in the target.

Core concepts & examples

Let’s break down the process with a practical example. Imagine we have incoming orders from an e-commerce platform (source) and we need to send it to our internal fulfillment system (target).

Source XML:

<orders>
<order>
<purchase_id>ORD-9876</purchase_id>
<client_details>
<firstname>Jane</firstname>
<lastname>Smith</lastname>
<contact_email>jane.smith@example.com</contact_email>
</client_details>
<line_items>
<item>
<sku>TS-BLUE-L</sku>
<item_name>Blue T-Shirt - Large</item_name>
<qty>1</qty>
<price>19.99</price>
</item>
<item>
<sku>MUG-LOGO</sku>
<item_name>Company Logo Mug</item_name>
<qty>2</qty>
<price>9.5</price>
</item>
</line_items>
</order>
<order>
<purchase_id>ORD-9877</purchase_id>
<client_details>
<firstname>John</firstname>
<lastname>Doe</lastname>
<contact_email>john.doe@example.com</contact_email>
</client_details>
<line_items>
<item>
<sku>TS-RED-M</sku>
<item_name>Red T-Shirt - Medium</item_name>
<qty>2</qty>
<price>19.99</price>
</item>
</line_items>
</order>
</orders>

Our fulfillment system requires the data in the following format:

Target XML:

<orders>
<order>
<orderReference>ORD-9876</orderReference>
<customerEmail>jane.smith@example.com</customerEmail>
<name>Jane Smith</name>
<products>
<product>
<productId>TS-BLUE-L</productId>
<quantity>1</quantity>
</product>
<product>
<productId>MUG-LOGO</productId>
<quantity>2</quantity>
</product>
</products>
</order>
<order>
<orderReference>ORD-9877</orderReference>
<customerEmail>john.doe@example.com</customerEmail>
<name>John Doe</name>
<products>
<product>
<productId>TS-RED-M</productId>
<quantity>1</quantity>
</product>
</products>
</order>
</orders>

Reader & writer

Zparse natively supports both reading and writing XML data, making it a powerful tool for any integration involving this format. These functions act as the entry and exit points for your data, allowing you to parse incoming XML and construct new XML to send to other systems.

XML reader (parser)

The XML reader is responsible for interpreting and parsing incoming XML data. It takes a raw XML string or file and transforms it into a structured object that Zparse can understand and manipulate. This allows you to easily access every element and attribute within the XML for use in your mapping.

A XML reader node

Use Cases:

  • Processing API responses: When you receive an XML response from an external API, the reader parses it so you can extract the specific data points you need.
  • Handling SOAP requests: Incoming SOAP requests use XML. The reader makes this data available to trigger and populate your workflows.
  • Reading uploaded files: If your process involves users uploading XML files, the reader can parse the contents of those files for processing.

XML writer

The XML writer does the opposite of the reader. It constructs a new, well-formed XML document from various data points within your Zparse workflow. You map your internal data to a target XML structure, and the writer builds the final output.

A XML writer node

Use Cases:

  • Creating API request bodies: When you need to send data to an external API that accepts XML, the writer assembles the required payload.
  • Generating SOAP responses: Construct a custom XML object to be sent as a SOAP response.
  • Generating XML files: Create structured XML files for export, reporting, or legacy system integration.

Mapping rules & transformations

To get from the source to the target, we apply a set of rules:

  1. Direct mapping (renaming): The element names are different, but the data is moved directly.
    • /order/purchase_id/order/orderReference
    • /order/client_details/contact_email/order/customerEmail

A graph which maps the order reference and the customer email

  1. Restructuring and mapping an array: We need to process the /line_items/item elements and create a new <products> section. For each item in the source, we map its fields to the new structure.
    • /item/sku/product/productId
    • /item/qty/product/quantity

A graph to iterate on products

  1. Value transformation (concatenation): The <name> element does not exist in the source. We must concatenate the <firstname> and the <lastname> elements.
    • <name> = "Jane" + " " + "Smith" = "Jane Smith"

A graph to concatenate the firstname and the lastname of a customer