# 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="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-0977e853194adf475f053bf4ae57c97678bab049%2Fstockeo-xml-settings.png?alt=media" 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="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-bd69a929de237c88d4fc8d824447acbf603a5f4b%2Fproduct-element.png?alt=media" 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](https://help.stockeo.solvenium.com/data-mapping/variants).
{% 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="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-cbbee697486598214146879a28fc573752d23bb6%2Fimage.png?alt=media" 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="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-345ee0385018d17c417fb8d0752da82de43deecf%2Fvariant-element-data-mapping-highlighted.png?alt=media" 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 %}

## 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="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-297222f964117abf2b6f377c7d666e62944a6371%2Fstockeo-select-node-with-specific-attribute.png?alt=media" 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 %}
