Attributes (in elements)

In this post, we will learn:

Introduction

Have you encountered the need to work with attributes in elements when processing product data and don’t know what they are for or how to use them? In MERGADO Editor, which is based on XML, you can easily work with them and increase your sales. Let’s talk about what attributes in elements are and how MERGADO can help you with them.

What are attributes?

Simply put: XML files consist of elements that carry information. And an attribute is a part of an element that specifies the meaning of the element. They are the bearers of the refining value. These values must always be enclosed in quotes or apostrophes.

Example: If we wanted to create an XML file with the names of the party attendees and their gender, the structure using an attribute would look like this:

<person gender="female">
    <firstname>Pavlína</firstname>
    <lastname>Nováková</lastname>
</person>

In the person element there is a gender attribute (dark blue color) with the value female (red color). This attribute specifies that Pavlína Nováková identifies herself as female.

Without the attribute, this entry could have this structure:

<person>
    <gender>female</gender>
    <firstname>Pavlína</firstname>
    <lastname>Nováková</lastname>
</person>

Example: Shoptet uses attributes for image descriptions:

<IMAGES>
   <IMAGE description="Zimní bunda Columbia (Barva Zelená, Velikost L)">https://cdn.myshoptet.com/název_obrázku.jpg</IMAGE>
</IMAGES>

:warning:  Google does not use element and attribute partitioning in its nomenclature as XML files do. It only uses the attribute label (for both elements and attributes). See Google specification.

What are attributes for?

Attributes in product feeds

For our personal purposes, it doesn’t matter what structure we write the birthday person in (the first example), as long as it’s functional. However, if we want to sell our products on various advertising portals, we may run into a problem. This is because some portals require sending product data with attributes in elements. Such portals are for example Ceneo, Heureka Availability, Shoptet and many more.

Example: Ceneo

<attrs>
    <a name="Producent">Nike</a>
</attrs>

Example: Heureka Availability

<item_list>
    <item id="314141-120">
    <stock_quantity>1</stock_quantity>
    <delivery_time orderDeadline="2023-04-17 12:00">2023-04-26 12:00</delivery_time>
</item>

Example: Shoptet

<IMAGES>
    <IMAGE description="Columbia Squish N’ Stuff (Barva Zelená, Velikost L)">https://cdn.myshoptet.com/název_obrázku.jpg</IMAGE>
    <IMAGE description="Columbia Squish N’ Stuff (Barva ČErvená, Velikost S)">https://cdn.myshoptet.com/název_obrázku.jpg</IMAGE>
</IMAGES>

Attributes and MERGADO Editor

You can work with attributes across the entire MERGADO Editor. With these edits you can:

  • Offer your items on portals that require the use of attributes.
  • Remove unwanted attributes and override attribute values.
  • Create product queries based on attributes.
  • Generally, we can work with attributes wherever element names appear: for example, in rules or MQL.

Attributes are recognized in the Editor by having the at sign @ at the beginning. Let’s show this with an example. We have the following input feed:

<SHOP>
    <SHOPITEM id="DEF87">
        <CODE>7DW890</CODE>
        <EXTERNAL_ID>ALERNARIVE798</EXTERNAL_ID>
        <NAME>Žehlicka</NAME>
        <IMAGES>
            <IMAGE description="desc image">www.zehlicka-image.com</IMAGE>
        </IMAGES>
    </SHOPITEM>
</SHOP>

The feed contains the SHOPITEM element, which has the id attribute in it. Next, we see the IMAGE element with the desc attribute. In the MERGADO Editor we see the above mentioned attributes with an at sign:

  • @id on the Elements page:
    image

  • @description on the Elements page:
    image

  • @id in the element input:
    image

  • @description in the element input:
    image

:information_source:  In the MERGADO Editor we can also encounter so-called special attributes. We can recognize them by starting with two at signs, e.g. @@POSITION or @@VALUE.

Examples of usage

1. In the rule form we target the element CODE of one specific variant which has the attribute @id (of the element VARIANT) with the value idvariant3:

<VARIANTS>
    <VARIANT id="idvariant3">
        <CODE>EEQ21</CODE>
        <UNIT>unit</UNIT>
        <FREE_SHIPPING>1</FREE_SHIPPING>
        <FREE_BILLING>1</FREE_BILLING>
    </VARIANT>
    <VARIANT id="idvariant4">
        <CODE>EEQ22</CODE>
        <UNIT>unit2</UNIT>
        <FREE_SHIPPING>0</FREE_SHIPPING>
        <FREE_BILLING>0</FREE_BILLING>
    </VARIANT>
</VARIANTS>

The path to the element CODE will be: VARIANTS | VARIANT { @id ~ "idvariant3" } | CODE.

2. On the Products page we are looking for a product with the defualt category with the attribute @id = 123:

<CATEGORIES>
    <DEFAULT_CATEGORY id="123">Appliances</DEFAULT_CATEGORY>
    <CATEGORY id="456">Electronics</CATEGORY>
</CATEGORIES>

The condition for the query will be: CATEGORIES | DEFAULT_CATEGORY | @id = "123".

Summary