XML Modifiers
Use XML modifiers to pull pieces of XML data into CSM in a usable format. For example, use XML modifiers with webhooks to parse, change, and use data between an external tool and CSM.
XML modifiers build on each other and typically must be used in conjunction with each other to return useful values. In addition, field tokens can be used in the modifiers. See also Webhook Modifier Examples.
All XML should be inside a root container so that you can use modifiers to successfully find it. Encapsulate the entire list in a root container as follows:
<directory>
<name id=”bob”>Value</name>
<name id=”Jane”>Value</name>
</directory>
The following modifiers can be applied to XML data. The examples use an XML collection that contains a list of books.
<?xml version="1.0"?>
<catalog> <book id="B1001"> <author>Johns, Jorge</author> <title>The Rest API</title> <genre>Computer</genre> <price>3.50</price> <publish_date>2016-03-15</publish_date> <description>An in-depth look at the REST API.</description> <in_stock>True</in_stock> </book> <book id="B1002"> <author>Boberson, Bob</author> <title>XML Modifiers and You</title> <genre>Fantasy</genre> <price> <priceUS>48.95</priceUS> <priceUK>48.96</priceUK> </price> <publish_date>2016-03-14</publish_date> <description>A book about XML Modifiers and you.</description> <in_stock>false</in_stock> </book>
</catalog>
Find Element
Returns an XML element with a specific name.
Example: Return the genre of the first book in an XML collection.
Modifier:
Result:
<genre>Computer</genre>
Find Element Collection
Returns an XML element that contains a series of common child elements.
Example: Find the collection of prices for the last book in the XML collection.
Modifier:
Result:
<price> <priceUS>48.95</priceUS> <priceUK>48.96</priceUK>
</price>
Find Element with Attribute
Returns an XML element with a specific name and attribute.
Example: Find a book with the id attribute of B1002.
Modifier: Find Element with Attribute (book .id .b1002)
Result:
<book id="B1002"> <author>Boberson, Bob</author> <title>XML Modifiers and You</title> <genre>Fantasy</genre> <price> <priceUS>48.95</priceUS> <priceUK>48.96</priceUK> </price> <publish_date>2020-03-14</publish_date> <description>A book about XML modifiers and you.</description>
</book>
First Child
Returns the first XML child element of the current element.
Example: Return the first book in the XML collection.
Modifier:
Result:
<book id="B1001"> <author>Johns, Jorge</author> <title>The Rest API</title> <genre>Computer</genre> <price>3.50</price> <publish_date>2016-03-15</publish_date> <description>An in-depth look at the REST API.</description> <in_stock>True</in_stock>
</book>
Has Child Element(s)
Returns whether an XML element has child elements.
Example: Check to see if there are any elements in the provided XML collection.
Modifier: Has Child Element(s) ()
Result: True
Last Child
Returns the last XML child element of the current element.
Example: Return the last book from the XML collection.
Modifier: Last Child ()
Result:
<book id="B1002"> <author>Boberson, Bob</author> <title>XML Modifiers and You</title> <genre>Fantasy</genre> <price> <priceUS>48.95</priceUS> <priceUK>48.96</priceUK> </price> <publish_date>2020-03-14</publish_date> <description>A book about XML modifiers and you.</description>
</book>
Logical from Element
Returns a logical value from a specified XML element.
Example: Check if the second book in the XML Collection is in stock.
Modifier: in_stock
Result: False
Number from Element
Returns a numerical value from a specified XML element.
Example: Find the price of the first book in the XML collection.
Modifier: price
Result: 3.5
String from Attribute
Returns a string value from a specified attribute on the current XML element.
Example: Find the ID of the first book in the XML collection.
Modifier: id
Result: B1001
String from Element
Returns a string value from a specified XML element.
Example: Retrieve the author's name from the first book in the XML collection.
Modifier: author
Result: Johns, Jorge
XPath (element)
Returns an XML element based on the provided XPath.
Version 1.0 of XPath is supported; version 2.0 is not supported.
Example: Retrieve the USA Price of the second book in the XML collection.
Modifier: //book[2]/price/priceUS
Result: <priceUS>48.95</priceUS>
XPath (value)
Returns a value based on the provided XPath.
Version 1.0 of XPath is supported; version 2.0 is not supported.
Example: Return the value of the second book in the XML collection.
Modifier: //book[2]
Result:
<book id="B1002"> <author>Boberson, Bob</author> <title>XML Modifiers and You</title> <genre>Fantasy</genre> <price> <priceUS>48.95</priceUS> <priceUK>48.96</priceUK> </price> <publish_date>2016-03-14</publish_date> <description>A book about XML Modifiers and you.</description> <in_stock>false</in_stock>
</book>