# Nestedness

**URL:** <https://forum.mergado.com/t/nestedness/748>\
**Category:** Elements\
**Tags:** mergado-2, elements, nestedness\
**Created:** [May 11, 2023, 12:13pm UTC](https://forum.mergado.com/t/nestedness/748 "2023-05-11T12:13:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lehuy](https://forum.mergado.com/user_avatar/forum.mergado.com/lehuy/32/280_2.png) [@lehuy](https://forum.mergado.com/u/lehuy)\
**Post date:** [May 11, 2023, 12:13pm UTC](https://forum.mergado.com/t/nestedness/748/1 "2023-05-11T12:13:21Z")

</div>

In this post, we will learn:

- [What is nestedness?](https://forum.mergado.com/t/nestedness/748#what-is-nestedness-2)
- [What is the purpose of nestedness?](https://forum.mergado.com/t/nestedness/748#what-is-the-purpose-of-nestedness-3)
- [What are the relationships between elements?](https://forum.mergado.com/t/nestedness/748#children-and-parents-4)
- [What types of files work with nestedness?](https://forum.mergado.com/t/nestedness/748#csv-cannot-handle-element-nesting-5)
- [Working with nested elements](https://forum.mergado.com/t/nestedness/748#working-with-nested-elements-in-mergado-editor-6)
- [Summary](https://forum.mergado.com/t/nestedness/748#summary-12)

## Introduction

Do you know where you might encounter the following images?

1. ![Snímek obrazovky z 2023-05-09 15-25-59](https://forum.mergado.com/uploads/default/original/1X/03c8d7686fbaa8738eee467d0ac450e2002071dd.png)

2. 

3. 

4. ![image](https://forum.mergado.com/uploads/default/original/1X/5f1ce380914541d805c2d8c821605fb7b85dac45.png)

1. The first image is from Google Chrome with some [XML feed](https://forum.mergado.com/t/elements/501#element-in-xml-feed-2) open.
2. The second image is from the Mergado Editor from the [Products page](https://forum.mergado.com/t/mergado-2-the-products-page/587).
3. The third image is from the Mergado Editor from the [Elements page](https://forum.mergado.com/t/mergado-2-elements/586).
4. The fourth image is from the CSV feed displayed in [Google Sheets generated by MERGADO Editor](https://www.mergado.com/blog/import-and-export-of-data-with-google-sheets?_gl=1*m7t291*_ga*MTI3NTg0MzczMC4xNjc4MjAxMDk1*_ga_5JED3N4VLV*MTY4MzgwODAwOC40My4wLjE2ODM4MDgwMDguMC4wLjA.).

And what connects all the images? All the images show the PARAM, PARAM\_NAME and VAL [elements](https://forum.mergado.com/t/elements/501). Only the fourth image shows the elements differently than the previous three. Why?

## What is nestedness?

_Nestedness_ is a **property of an element**. An element is nested if it is between the [start tag and end tag](https://www.w3schools.com/xml/xml_elements.asp) of another element in the XML feed. In the example above, the PARAM\_NAME element is directly nested within the PARAM element. The VAL element is also directly nested within the PARAM element.

![Selection_001](https://forum.mergado.com/uploads/default/original/1X/1a09de95e70da7698023d0b1f3e53b92d2358356.png)

## What is the purpose of nestedness?

[Different ad systems](https://www.mergado.com/supported-channels) have their own formats with different specifications. Some do not work with nestedness and others do. Therefore, **we need to adapt our feeds to this specification**.

Besides, it usually makes sense - when we see that an element is nested in another element, we think that the two elements probably have something in common and belong together. We **most often see this with parameters and deliveries**.

Example with PARAM, PARAM\_NAME and VAL:

![image](https://forum.mergado.com/uploads/default/original/1X/ae88aebb7eb8f964d757c50904ad7f1f14f8450d.png)

PARAM\_NAME is the element containing the name of the parameter (Product type). VAL is the element containing the value of the parameter (Digital player). PARAM **wraps and unifies these two elements in one place**. So then we know that the Product type is Digital player, and we don’t have to search for this information in a fragmented way in different parts of the XML feed.

## Children and Parents

If an element is directly nested within another element, the two elements have a _relationship_ with each other. We call the nested element a _child_ and the element it is nested in a _parent_. From the example above, the parent is the PARAM element and its children are the PARAM\_NAME and VAL elements. At the same time, the elements PARAM\_NAME and VAL are siblings.

You may have noticed that in the first image (in the XML feed), the **children are slightly more indented from the left compared to the parents**. This is also the case in the second and third images, because [MERGADO Editor sees elements the same way as the XML feed](https://forum.mergado.com/t/elements/501#element-in-mergado-editor-4). That’s why it also shows them _offset_.

> ℹ&nbsp; While we do have parent and child elements, we no longer say that an element is a grandparent of another element. That’s usually irrelevant.

> ℹ&nbsp; Even a parent element can have its own text value. In reality, however, we don’t usually encounter such cases.   
>   
> ![image](https://forum.mergado.com/uploads/default/original/1X/f1b0c991064aa345d988a0cc5a6a4ee14d055c0d.png)

> 💡 There is no theoretical limitation on the depth of the element’s nesting. In our practice, we have encountered a higher number of nestedness levels in Shoptet formats (7 levels) and in Upgates formats (9 levels). Thus, the parent element has a child that has another child that has another child, etc.
> 
> ![pasted image 0](https://forum.mergado.com/uploads/default/original/1X/c5ee7e2b8a2b0aea30fd39c052227389b84dcb86.png)

## **CSV cannot handle element nesting**

Now we come to our original question - why? Why does CSV show element nesting differently than XML and Mergado Editor? To be fair: CSV alone cannot handle element nestedness. Only XML and Mergado Editor have this capability.

![image](https://forum.mergado.com/uploads/default/original/1X/5f1ce380914541d805c2d8c821605fb7b85dac45.png)

You might be thinking, “But I can see from the image that the PARAM\_NAME and VAL elements are nested inside the PARAM element!” You can see that they are written there as `parent | child`. However, such an entry is not produced by CSV, but by the Mergado Editor.

> ℹ&nbsp; [The vertical “|”](https://en.wikipedia.org/wiki/Vertical_bar) is typed on the English keyboard with the `Shift + \` keyboard shortcut.

## Working with nested elements in Mergado Editor

### 1. How do we create a nested element?

On the [Elements page](https://forum.mergado.com/t/mergado-2-elements/586), click the “+” icon next to the parent element of our choice.

![Selection_003](https://forum.mergado.com/uploads/default/optimized/1X/98424a5aecfccb96badb0e039c0c9d887b053280_2_690x29.png)

This will open a small form to create the element.

![image](https://forum.mergado.com/uploads/default/optimized/1X/4177213c66e59ea47c569f42cba81c0295e923f0_2_690x64.png)

> ℹ &nbsp;The procedure for creating a nested element is somewhat similar (but not exactly the same) to the procedure for creating an un-nested element. In this case, however, we are clicking on different buttons:
> 
> ![image](https://forum.mergado.com/uploads/default/original/1X/ec8effd439f7b6204a055dd74e77e38a84065e13.png)

### 2. How do we recognize nested elements?

In the Editor we come across **2 types of views**. We have already shown the first type of view in the second (Products page) and third (Elements page) image from the introduction - you can see the nestedness in the same way as in XML, **by the indentation**.

 ![image](https://forum.mergado.com/uploads/default/original/1X/2acfe3e39a832873986574a2c4d921c7b95efa87.png)

We came across the second type of display in the fourth image (CSV). In addition, it also occurs at various times throughout the Editor - from the Products page to the History page. This is the `parent | child` view.

![](https://lh6.googleusercontent.com/wZGDa9HyJ2Mc65SKEmj0UFiy22rvOEKvOVlQ5QLAzH64oNhTIj1F_OopxYYVxyE0x0-9_6liYhkmiNN3H02mZk6BW1GsD4h7-uiZ19c2p1EvXqngKXqrvXYgM-QOq64hsNLsmv-9GVKbESvcad5wXvc)

### 3. How to select/target a nested element?

![image](https://forum.mergado.com/uploads/default/original/1X/889792a52f692eeb1e2c9a928e96ebcbe848241e.png)

Use the pattern `parent | child`. For example, if we want to know what Product type we have. So we select the VAL element with the value Digital player, which is nested in the PARAM element, type `PARAM | VAL`.

> ℹ &nbsp;We call the entire `PARAM | VAL` expression [element path](https://forum.mergado.com/t/element-path/753#what-is-path-to-element-2).

### 4. What to watch out for?

a) You **cannot specify a [root element](https://www.w3schools.com/xml/xml_syntax.asp)**, such as SHOP, or item elements, such as ITEM or SHOPITEM, in the element path. We can only work with elements that we see on the Elements page.

 ![image](https://forum.mergado.com/uploads/default/original/1X/45b04be3227ead0dcced719ced486e95684ef818.png)

 ![image](https://forum.mergado.com/uploads/default/original/1X/9f10bb1156b99db32c576d5f147bac521619dad4.png)

b) **The space before and after the vertical bar is important and cannot be omitted**. An example of correct notation is `PARAM | VAL`. Examples of incorrect notation are `PARAM|VAL`, `PARAM |VAL` or `PARAM| VAL`.

c) What if **[we have more than one parameter? And we want to find out the value of only one of them](https://forum.mergado.cz/t/prace-s-parametry-v-mergadu-2/2249#jak-vnmme-parametry-2)**, e.g. how do we find out what display the product has?

 ![image](https://forum.mergado.com/uploads/default/original/1X/89ca029333636fb484060f6275819e6db13958d2.png)

In the figure, there are two parameters. Using the `PARAM | VAL` path, we can get to the Digital player value, but also the Touch value. This means that one path leads to more than one value. If this happens, we are dealing with [multi-value element](https://forum.mergado.com/t/what-is-a-multi-value-element/589) (in our case, the PARAM element is multi-value).

 ![image](https://forum.mergado.com/uploads/default/original/1X/bd07d60be6e468ea0f028cf32846ba47f9d16569.png)

So how do we get to the value of Touch only? We have multiple options. They all involve using [conditions](https://forum.mergado.com/t/conditions-in-the-element-path/757) bound to the PARAM element in the `PARAM | VAL` path:

- `PARAM { @@POSITION = 2 } | VAL`  
– the loose translation of the path is: find the PARAM element, but only the second one, and go to its VAL element
- `PARAM { PARAM_NAME = "Display type" } | VAL`  
– the loose path translation is: find a PARAM element, but only one that has a PARAM\_NAME child with the value Display type, and go to its VAL element

A **weakness** of using the [@@POSITION](https://forum.mergado.com/t/position/766) special attribute may be that even though we would have a **variable occurrence of parameters** across products, the second parameter would be targeted for all of these products, even if the second parameter is not a Display type for some products. From this perspective, it is therefore safer to use the option with `PARAM_NAME = "Display type"`, where the Display type parameter is selected regardless of its position (so that even if it is, say, 50th in order, the correct parameter is selected).

d) Some elements may seemingly **appear both un-nested and nested** under various other elements:

 ![image](https://forum.mergado.com/uploads/default/original/1X/bbfe70e0476b08aa40cb084a32b19ecea81fb74f.png)

There is a second parameter in the image above, but (unlike the first) it is nested under the VARIANT element. **These are different elements!** It can be helpful to write their paths, which are also different:

1. `PARAM | PARAM_NAME`  
`PARAM | VAL`
2. `VARIANTS | VARIANT | PARAM | PARAM_NAME`  
`VARIANTS | VARIANT | PARAM | VAL`

### 5. What is the difference between working with nested and un-nested elements?

We work with un-nested elements **the same way as with nested elements**. How do I select/target a un-nested element? Just type its name, as that is the way to get to it, since the element is un-nested. If the element is [multi-value](https://forum.mergado.com/t/what-is-a-multi-value-element/589), we use [conditions](https://forum.mergado.com/t/conditions-in-the-element-path/757) – with the special attribute [@@POSITION](https://forum.mergado.com/t/position/766), or we can use the special attribute [@@VALUE](https://forum.mergado.com/t/value/751).

> ℹ &nbsp;Mergado 1 could not handle element nesting compared to [MERGADO 2](https://forum.mergado.com/t/what-is-mergado-2/761). The way to work around this was to load the nested elements as un-nested elements, just with a modified name. For example, PARAM and its children PARAM\_NAME with the value Product type and VAL with the value Digital player were loaded as a single element named PARAM|Product\_type with the value Digital player.

## Summary

- [What is nestedness?](https://forum.mergado.com/t/nestedness/748#what-is-nestedness-2)  
Nestedness is a property of an element. An element is nested if it is between the [start tag and end tag](https://www.w3schools.com/xml/xml_elements.asp) of another element in the XML feed.

- [What is the purpose of nestedness?](https://forum.mergado.com/t/nestedness/748#what-is-the-purpose-of-nestedness-3)  
Different ad systems have their own formats with different specifications. Some do not work with nestedness and others do. Therefore, we need to adapt our feeds to this specification.

- [What are the relationships between elements?](https://forum.mergado.com/t/nestedness/748#children-and-parents-4)  
If an element is directly nested within another element, the two elements have a relationship with each other. We call the nested element a child and the element into which we nest is a parent.

- [What file types work with nestedness?](https://forum.mergado.com/t/nestedness/748#csv-cannot-handle-element-nesting-5)  
Mergado Editor supports XML, JSON, CSV and Google Sheets. Of the listed file types, it works with XML and JSON. The other types can’t work with nestedness, the Editor must help them.

- [Working with nested elements](https://forum.mergado.com/t/nestedness/748#working-with-nested-elements-in-mergado-editor-6)  
To work with nested elements, we just need to know that nestedness is indicated by a left indent or an underscore.
