Skip to main content

XML Template

XML is a popular feed format used by major online marketplaces.

  • Why use a feed in XML format? The XML format provides more control over products included in the feed.
  • Where are XML feeds used? XML feeds are supported by many shopping engines, including Google Shopping, Facebook, eBay.
  • What are XML feed peculiarities? Each node of data should be defined individually. For example, if a product has a unique attribute, this attribute field should have a name in order to output it in the feed.
Typical XML schema for Google Shopping.
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Google Shopping den_test_store</title>
<link>https://den-test-store.myshopify.com</link>
<description>Data feed</description>
{% for variant in context.product_variants %}
<item>
<g:id><![CDATA[{{ variant.id }}]]></g:id>
<g:item_group_id><![CDATA[{{ variant.parent_id }}]]></g:item_group_id>
<title><![CDATA[{{ variant.title | t | truncate: 70, "" }}]]></title>
<link><![CDATA[{{ variant.url }}]]></link>
<g:price>{{ variant.price | currency }}</g:price>
<description><![CDATA[{{ variant.body_html | strip_html | t | truncate: 5000, "" }}]]></description>
<g:product_type><![CDATA[{{ variant.collection_title | t }}]]></g:product_type>
<g:google_product_category><![CDATA[{{ variant.mapping_collection_title }}]]></g:google_product_category>
<g:image_link><![CDATA[{{ variant.image_url }}]]></g:image_link>
{% for image in variant.parent_image_urls offset:1 %}
<g:additional_image_link><![CDATA[{{ image }}]]></g:additional_image_link>
{% endfor %}
<g:condition>new</g:condition>
<g:availability>{% if variant.in_stock %}in stock{% else %}out of stock{% endif %}</g:availability>
<brand><![CDATA[{{ variant.vendor }}]]></brand>
{% if variant.weight_grams != 0 %}
<weight><![CDATA[{{ variant.weight_grams }} g]]></weight>
{% endif %}
<g:gender><![CDATA[]]></g:gender>
<g:age_group><![CDATA[]]></g:age_group>
<g:mpn><![CDATA[{{ variant.sku }}]]></g:mpn>
<g:gtin><![CDATA[{{ variant.barcode }}]]></g:gtin>
{% if variant.vendor != "" %}
<g:identifier_exists><![CDATA[true]]></g:identifier_exists>
{% else %}
<g:identifier_exists><![CDATA[false]]></g:identifier_exists>
{% endif %}
</item>
{% endfor %}
</channel>
</rss>

Customizing XML Template

Mulwi Shopping Feeds app provides a set of default templates for popular online marketplaces. However, if you need individual feed output for some marketplace, you can customize the default XML template.

Template customization overview

The feed modification is made with the help of Liquid variables and Liquid filters. A brief explanation of working with variables.

note

Characters like < and & are illegal in XML elements. Their appearance in the string will generate an error because the parser interprets it as the start of a new element and the start of a character entity, respectively.

Enclose all patterns in a CDATA block

<attribute><![CDATA[{{ pattern }}]]></attribute>

In this case, the xml data feed will be valid.

How to list products in the feed

To fill the XML feed with the list of products, you need to create a cycle within the context.products object.

Include product attributes you need to be present in the feed, for example, product ID, product title, product URL.

product cycle block
INPUT
{% for product in context.products %}
<item>
<id><![CDATA[{{ product.id }}]]></id>
<title><![CDATA[{{ product.title }}]]></title>
<link><![CDATA[{{ product.url }}]]></link>
</item>
{% endfor %}
OUTPUT
<item>
<id>
<![CDATA[ 7259352105158 ]]>
<id>
<title>
<![CDATA[ Super Heroes ]]>
</title>
<link>
<![CDATA[ https://store.myshopify.com/products/super-heroes-dropship-attack-set?om=8179 ]]>
</link>
</item>

How to list product variants in the feed

The list of product variants in the feed can be generated with a cycle within the context.product_variants object.

Here is an example of how to fill the feed with product variants with a price greater than 10.

product variant with a price greater than 10
INPUT
{% for variant in context.product_variants %}
<item>
{% if variant.price > 10 %}
<name>{{ variant.title }}</name>
{% endif %}
</item>
{% endfor %}
OUTPUT
<item>
<name>
<![CDATA[ Super Heroes ]]>
</name>
</item>

How to list product collections in the feed

You can generate a feed specifically for products within a certain collection as shown:

list of products from specific product collection
INPUT
{% for collection in context.collections %}
{% for product in context.products %}
{% if collection.title == "TOYS" %}
<item>
<product_name><![CDATA[{{ product.title }}]]></product_name>
<collection><![CDATA[{{ collection.title }}]]></collection>
</item>
{% endif %}
{% endfor %}
{% endfor %}
OUTPUT
<item>
<product_name>
<![CDATA[ Mobile Command Center ]]>
</product_name>
<collection>
<![CDATA[ TOYS ]]>
</collection>
</item>
<item>
<product_name>
<![CDATA[ Fun Family Fair ]]>
</product_name>
<collection>
<![CDATA[ TOYS ]]>
</collection>
</item>

How to call product variants within the product context

You can call variant collection object within the product context as shown in the example:

call product variants within the product context
INPUT
{% for product in context.products %}
<product>
<product_id>{{ product.id }}</product_id>
<product_name>{{ product.title }}</product_name>
</product>
{% for variant in product.variants %}
<variant>
<variant_id>{{ variant.id }}</variant_id>
<variant_name><![CDATA[{{ variant.title }}]]></variant_name>
</variant>
{% endfor %}
{% endfor %}
OUTPUT
<product>
<product_id>
7259352236230
</product_id>
<product_name>
Super Heroes Attack
</product_name>
</product>
<variant>
<variant_id>
41805189120198
</variant_id>
<variant_name>
<![CDATA[ Super Heroes Attack ]]>
</variant_name>
</variant>
<product>
<product_id>
7259352268998
</product_id>
<product_name>
Mobile Command Center
</product_name>
</product>
<variant>
<variant_id>
41805189152966
</variant_id>
<variant_name>
<![CDATA[ Mobile Command Center ]]>
</variant_name>
</variant>