In this post, we will learn:
- What is Element-Path?
- What is path to element?
- How is the path to the element written?
- Where do we use element paths?
- Summary
Mergado Editor perceives elements in the same way as XML feeds do. This is the basis for all the work with elements, where we encounter, for example, nested or multi-value elements. And to be able to modify specific element values, we need to have a way to target those values. That’s what we have Element-Path for.
What is Element-Path?
Element-Path is a language, authored by us (Mergado), that we use to write paths to elements (and their values).
What is path to element?
A path to element is a tool we use to target element values. By targeting, we mean that we either want to take a value from an element and work with it somewhere else, or we want to write to it and modify it.
Example: if we want to target a product name (e.g. the value of the NAME element), the path would be “NAME”. The Mergado Editor reads this path and knows which element to look at and what value to take/modify.
In Mergado 1, the Element-Path language could not be used, as there were no multi-value elements or element structure in that version.
Element-Path vocabulary and grammar
Since Element-Path is a language, Element-Path, like regular languages, has a vocabulary (the elements that can be used in paths to elements) and a grammar (a set of rules for how paths are written).
Example: if we compare the Element-Path language to English, then a path to an element is analogous to a sentence:
- Different sentences with different content use the words and grammar of the English language.
- Different paths to different elements use the words and grammar of the Element-Path language.
The names of all the elements
The Element-Path vocabulary includes the names of all elements. The simplest path is one that consists of the name of the element itself.
Example: you may have used the Rewrite rule to edit a product description, i.e. you have overridden the value of the DESCRIPTION element. This means that you have entered the text “DESCRIPTION” in the field for the element.
Nestedness
If you want to target a nested element add the element’s parent name and the vertical bar | (another addition to the vocabulary) to the path before the element.
Example: we want to target the information parameter - the NAME element nested under the INFORMATION_PARAMETER element.
Since the NAME element for the information parameter is nested under the INFORMATION_PARAMETER element (which is nested under INFORMATION_PARAMETERS), the path to its values looks like this:
The Mergado Editor reads the path by first going to the INFORMATION_PARAMETERS element, then to its children, where it overwrites the value of the NAME element within the INFORMATION_PARAMETER element.
Conditions
The conditions in the element path are a filter that allows us to filter values for multi-value elements within the path. They are written in curly brackets { }. Conditions are an important part of Element-Path, so we recommend you read the detailed post on conditions in element paths.
Example: We want to modify the value of the Material information parameter.
This is a nested VALUE element and the path looks like this:
Except that the path targets all values of the VALUE element
and we only want to modify the value for Material. We will therefore use the condition. The final path will therefore be:
Special attributes
There are special attributes @@POSITION and @@VALUE. These attributes can be used in conditions. You can read more about them in the individual posts.
Example: IMGURL_ALTERNATIVE { @@POSITION >= 2 }
Example: CATEGORIES | CATEGORY { @@VALUE != "Toys" }
If you can think of another special attribute you would use, email us!
MQL in Element-Path
We don’t stop at special attributes. In fact, we can type anything into conditions that we can type into MQL query. This adds the entire vocabulary of MQL to the Element-Path vocabulary. Again, we recommend reading the detailed post on element path conditions.
Example:
VARIANTS | VARIANT { PARAMETERS | PARAMETER { NAME = "Size" } | VALUE = "M" AND PARAMETERS | PARAMETER { NAME = "Material" } | VALUE = "Cotton" } | STOCK | WAREHOUSES | WAREHOUSE | NAME
Syntax errors
Just as you can make spelling or grammatical errors in English, you can make syntax errors in Element-Path. If we make a syntax error in our writing, Mergado Editor usually warns us about it. As an example: omission of closing quotation marks in condition in path to element:
The path to element or to values?
Throughout this post we write path to element, but you may have come across path to element value or similar other forms. All of these shapes are fine. There are no rules about writing paths - it always depends on the writer’s judgement and the context of the whole text.
In general, the form path to the value of the element, i.e. with the word value, is more accurate because path targets the value of the element, not the element itself.
However, if we talk about simple elements, the path to element form is clear enough, since the element has only one value. So we know that the path targets that one value. But if we talk about multi-value elements that have multiple values, it is more appropriate and accurate to use the form with the word value if the path targets only one specific value.
Here are some examples:
- element/attribute path,
- element/attribute,
- IMGURL element,
- IMGURL element path,
- path to value 69 of PRICE_VAT element,
- path to parameter value,
- path for element,
- element path,
- element whose path,
- value whose path,
- for value 69 the path is,
- path
- and many others.
How to read path?
The rules for reading paths to elements are not explicitly given, but we recommend following these principles to better understand how the paths themselves work, i.e. what values they target in the result of the path.
Principles of path reading:
- Read sequentially from left to right.
- We read element names and special attributes intuitively as they come to us. E.g. “element ITEM_ID” or just “ITEM_ID” etc.
- For unnested elements, just read “target the element” (or target the element value or all element values).
- For paths with nested elements, start with “take” or another synonym.
- We read vertical bars as “and the nested element under it” or “and its child”, etc.
- For the last nested element, we say “and (in such an element) target the nested element under it” or “and (in such an element) target its child”, etc.
- Conditions: we read the left curly bracket as “whose underlying nested element” or “whose child”, etc.
Example 1: ITEM_ID
“We are targeting the ITEM_ID element.”
Example 2: INFORMATION_PARAMETERS | INFORMATION_PARAMETER { NAME = "Material" } | VALUE
We can read it like this:
- “Take an INFORMATION_PARAMETERS element and an INFORMATION_PARAMETER element nested under it, whose NAME element nested under it has a value equal to Material, and in such INFORMATION_PARAMETER element target the VALUE element nested under it.”
- “Take INFORMATION_PARAMETERS and its child INFORMATION_PARAMETER whose child NAME has a value equal to Material, and in such INFORMATION_PARAMETER target its child VALUE.”
- etc.
Example 3: CATEGORIES | CATEGORY { @@VALUE != "Toys" }
Let’s read it, for example, as follows:
- “We take the CATEGORIES element and target its CATEGORY child whose value is not equal to Toys.”
- “We take the CATEGORIES and target the submerged CATEGORY under, whose value is not equal to the Toy.”
What is Element-Path for?
Element-Path is used to write paths to elements, which we then use to target element values.
Where do we target element values?
We will use targeting element values (thus also Element-Path) when working in the Mergado Editor in many places, in general everywhere we work with elements:
-
In a simple selection form - Oneliner - on the Products page when creating conditions. In the first or third part of the condition it is possible to write paths to elements.
-
In the form for your own MQL query.
-
When sorting products on the Products page.
-
In the table view products when adding columns.
-
In the form of some rules in the field for the element – refers to the rules Rewrite, Find and Replace, Bulk rewriting by query, Bulk rewriting by values, Bulk copy values, Truncate value, Letter case converter, Round number, Remove diacritics , Set UTM parameters, Remove HTML tags, Calculation and Add a value to a multi-value element.
-
In the headers of import files, which we upload via the rule Data file import.
-
On the page of the values of a specific element (after clicking on the Elements page).
-
When creating and editing variables.
Examples of targeting
We covered dozens of examples of targeting for different formats in a separate post Element-Path: Examples of targeting (Heureka, Google, Shoptet).
Summary
- What is Element-Path?
Element-Path is a language used to write paths to elements.
- What is the path to the element?
An element path is a tool we use to target element values.
- How is the path to the element written?
- We can write element names in the path.
- Immersion is indicated by a vertical bar.
- To specify the path, use conditions that are written in braces.
- Where do we use element paths?
We will use paths almost throughout the Mergado Editor, in short, everywhere we work and target elements and their values.