Skip to main content

Understanding XML path

XML path is a syntax used to navigate through elements in an XML document. Think of it as an address system for finding specific information. When you have a complex XML file, it allows you to pinpoint the exact piece of data you need.

This is crucial for data mapping, as it lets you accurately select source data to transform and move to a target system.

warning

Zparse does not support the full XPath specification, only basic selection.

XML example

We will use the following XML document, which contains a list of customer orders, as the basis for all our examples.

<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>
<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>
</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>
<items>
<item>
<sku>TS-RED-M</sku>
<item_name>Red T-Shirt - Medium</item_name>
<qty>2</qty>
<price>19.99</price>
</item>
</items>
</order>
</orders>

Basic selection

You can select nodes by defining a path starting from the root. The forward slash / is used to separate elements in the path.

PathResult
/ordersSelects the root element <orders>.
/orders/orderSelects all <order> elements.
/orders/order/items/itemSelects all <item> elements.