parse_xml
Coming soon
Parses an XML string into a Liquid object. Useful for processing XML feeds, API responses, and file imports.
{% assign data = xml_string | parse_xml %}
{% log data %}Syntax
{{ xml_string | parse_xml }}Parameter
Description
xml_string
A string containing valid XML data
Return Value
Returns a Liquid object representing the XML structure. Elements become object keys, text content becomes values, and repeated elements become arrays.
Examples
Parse an XML API response:
{% http url:"https://api.example.com/products.xml" method:"GET" as response %}
{% assign data = response.body | parse_xml %}
{% for product in data.products.product %}
{% log product.title %}
{% endfor %}Parse an uploaded XML file:
{% assign data = file.content | parse_xml %}
{% log data %}Parse an XML feed and extract items:
Process XML product feed:
Notes
Elements with text content are converted to their text value directly
Repeated sibling elements with the same name become arrays
Nested elements are preserved in the object structure
Element attributes are not included; use
parse_xml_attrsto keep themSee also:
parse_xml_attrs,parse_json,parse_csv
Last updated