# XML

XML is a flexible, text-based format used for structuring and storing data, commonly used in web services and data exchange between systems.

<figure><img src="/files/x1DZMbBwSXk9z0uNFYuo" alt=""><figcaption><p>XML settings</p></figcaption></figure>

## Product Element

The key information required by Stockeo is the node name that contains the data for a single product.

```html
<Products>
    <Product>
        <Code>0260</Code>
        <Title>Sitting Jazz Band Saxophonist</Title>
        <Price>13.73</Price>
        <RRP>32.95</RRP>
        <AvailableStock>181</AvailableStock>
        <Barcode>5050140026007</Barcode>
        <Description>A sitting jazz man, playing the saxophone.</Description>
        <Image>https://www.hill-interiors.com/images/giant/0260.jpg</Image>
    </Product>
    <Product>
        <Code>0261</Code>
        <Title>Sitting Jazz Band Trumpeter</Title>
        <Price>13.73</Price>
        <RRP>32.95</RRP>
        <AvailableStock>162</AvailableStock>
        <Barcode>5050140026106</Barcode>
        <Description>Bring timeless musical elegance to any setting with the Sitting Jazz Band
            Trumpeter.</Description>
        <Image1>https://www.hill-interiors.com/images/giant/0261.jpg</Image>
    </Product>
</Products>
```

In such a case above enter `Product` in the Product Element field.

<figure><img src="/files/hJ7IPC0XzW9uZgZmCtUV" alt=""><figcaption><p>Product Element</p></figcaption></figure>

Fields associated with the product are relative to the node used as Product Element:

* Title
* Description
* Image URL
* Product Type
* Tag
* Vendor
* Product Metafield

## Variant Element

Fill in this field only when variants are nested in the product node.

{% hint style="info" %}
If variants are in separate nodes at the product level and have a node with the same value for all variants of a specific product like product name, parent SKU, or parent ID, leave this field empty. For more information navigate to [Variants](/data-mapping/variants.md).
{% endhint %}

```xml
<Products>
    <Product>
        <Code>0260</Code>
        <Title>Sitting Jazz Band Saxophonist</Title>
        <Description>A sitting jazz man, playing the saxophone.</Description>
        <Image>https://www.hill-interiors.com/images/giant/0260.jpg</Image>
        <Variants>
            <Variant>
                <VariantCode>0260S</VariantCode>
                <Price>13.73</Price>
                <RRP>32.95</RRP>
                <AvailableStock>181</AvailableStock>
                <Barcode>5050140026007</Barcode>
                <Option>Small</Option>
            </Variant>
            <Variant>
                <VariantCode>0260M</VariantCode>
                <Price>20.59</Price>
                <RRP>32.95</RRP>
                <AvailableStock>56</AvailableStock>
                <Barcode>5050140026008</Barcode>
                <Option>Medium</Option>
            </Variant>
            <Variant>
                <VariantCode>0260L</VariantCode>
                <Price>30.89</Price>
                <RRP>32.95</RRP>
                <AvailableStock>74</AvailableStock>
                <Barcode>5050140026009</Barcode>
                <Option>Large</Option>
            </Variant>
        </Variants>
    </Product>
</Products>
```

In such a case above enter `Variants/Variant` in the Variant Element field.

<figure><img src="/files/s4P8Pjku5G6tDGIjVAyu" alt=""><figcaption><p>Variant Element</p></figcaption></figure>

Fields associated with the variant are relative to the node used as Variant Element:

* SKU
* Barcode
* Compare at price
* Continue selling when out of stock
* Charge tax
* Cost per item
* Market Price
* Price
* Quantity
* Weight
* Variant Metafield
* Option

An example feed mapping, where variant nodes are embedded within product nodes, may look as follows:

<figure><img src="/files/ugSXTAxj7IgSgbT0DY2d" alt=""><figcaption><p>Data Mapping section with Variant Element</p></figcaption></figure>

## Basic Data Mapping

In most XML feeds the data you need is stored as text inside nodes, and mapping it is straightforward - just enter the node name or the path to a nested node.

The examples below use the following XML feed:

```xml
<Product id="3378">
  <SKU>WC-1001</SKU>
  <Title>Wooden Clock With Nickel Details</Title>
  <Category>Clocks</Category>
  <Price currency="EUR">29.99</Price>
  <Stock>443</Stock>
  <Images>
    <Image>https://example.com/images/wc-1001-front.jpg</Image>
    <Image>https://example.com/images/wc-1001-side.jpg</Image>
  </Images>
</Product>
```

In this example the Product Element is `Product`.

### Node name

To get the text content of a child node, enter the node name. For example, to get the product title:

```
Title
```

### Path to a nested node

Use a **slash** (`/`) to navigate deeper. For example, to reach the first image inside `Images > Image`:

```
Images/Image
```

### Pick a specific item from a list with \[index]

When a node appears multiple times (like several `<Image>` nodes), you can pick a specific one by its position. The numbering starts at 1.

For example, to get the **second** image:

```
Images/Image[2]
```

### Read an attribute with @

Some feeds store data in XML attributes rather than as text content. To read an attribute, type the **@** sign followed by the **attribute name**.

For an attribute on the product node itself (e.g. if `<Product id="3378">`):

```
@id
```

For an attribute on a nested node, combine the path with `@`. For example, to get the `currency` attribute from the `<Price>` node:

```
Price/@currency
```

You can also combine a path, an index, and an attribute. For example, if images were stored as `<Image url="..."/>`, you would get the URL of the second image like this:

```
Images/Image[2]/@url
```

{% hint style="info" %}
XML namespaces (prefixes like `xml:`, `iaiext:`, etc.) are automatically stripped by Stockeo. When referencing attributes, use the name without the prefix. For example, `xml:lang` becomes just `lang`.
{% endhint %}

### Reading data from Variant Element attributes and values

In some cases, values need to be retrieved directly from a variant element's attribute or its node value.

```xml
<products>
  <product product_id="2001">
    <prices>
      <price currency="PLN" retail_price="299.99" wholesale_price="249.99" />
      <price currency="EUR" retail_price="69.99" wholesale_price="58.99" />
    </prices>
    <variants>
      <variant v_id="501" sku="TSHIRT-BLK-S" ean="5901234560011">15</variant>
      <variant v_id="502" sku="TSHIRT-BLK-M" ean="5901234560028">20</variant>
      <variant v_id="503" sku="TSHIRT-BLK-L" ean="5901234560035">12</variant>
      <variant v_id="504" sku="TSHIRT-BLK-XL" ean="5901234560042">8</variant>
      <variant v_id="505" sku="TSHIRT-BLK-XXL" ean="5901234560059">5</variant>
      <variant v_id="506" sku="TSHIRT-BLK-XXXL" ean="5901234560066">2</variant>
    </variants>
  </product>
</products>
```

To read an attribute from a variant element, use a Liquid formula with the `_attributes` object and specify the attribute name.

```
{{ _attributes.sku }}
```

To read the value of the variant element node itself, use `value` in the mapping field or in Liquid.

```
{{ value }}
```

A sample mapping for this type of XML is shown below:

<figure><img src="/files/5EK8YdnlGaclsri5O7FQ" alt="Data mapping configuration showing how to read values from Variant Element attributes and element values"><figcaption><p>Data mapping example using Variant Element attributes and values</p></figcaption></figure>

## Advanced Data Mapping with Liquid

For anything beyond the expressions above — such as picking a node by the value of its attribute — use a Liquid template.

{% hint style="warning" %}
Selecting a node by attribute value (e.g. "get the name where language is English") is **not** supported with simple expressions. Use Liquid instead as shown below.
{% endhint %}

Consider the following XML where the product title is available in multiple languages:

```xml
<product id="3378" currency="EUR" code_on_card="01269" type="regular" vat="23.0">
  <names>
    <name lang="eng"><![CDATA[Wooden Clock With Nickel Details]]></name>
    <name lang="hun"><![CDATA[Fa óra nikkel részletekkel]]></name>
    <name lang="pol"><![CDATA[Drewniany zegar z niklowymi dodatkami]]></name>
  </names>
  <stock quantity="443" available_stock_quantity="443"/>
  <images>
    <large>
      <image priority="1" url="https://example.com/images/3378-1.jpg"/>
      <image priority="2" url="https://example.com/images/3378-2.jpg"/>
    </large>
  </images>
</product>
```

### Select a node by attribute value

To extract the product title from the `<Name>` node where the language is `eng`, use the `where` filter:

{% tabs %}
{% tab title="Stockeo setting" %}

<figure><img src="/files/3wzUJ1rUNOsYG8L3fQE9" alt="Select node with a specific attribute in the Stockeo automation"><figcaption><p>Select node with a specific attribute in the Stockeo automation</p></figcaption></figure>
{% endtab %}

{% tab title="Copy this setting" %}

```
{{ names.name | where: "_attributes.lang", "eng" | map: "value" | first }}
```

{% endtab %}
{% endtabs %}

### Select an image by attribute value

To pull the URL of the image with `priority="1"`:

{% tabs %}
{% tab title="Copy this setting" %}

```
{{ images.large.image | where: "_attributes.priority", "1" | map: "_attributes" | map: "url" | first }}
```

{% endtab %}
{% endtabs %}

And for the second image (`priority="2"`):

{% tabs %}
{% tab title="Copy this setting" %}

```
{{ images.large.image | where: "_attributes.priority", "2" | map: "_attributes" | map: "url" | first }}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.stockeo.solvenium.com/data-mapping/format/xml.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
