Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ArgumentTypeDescription
XMLStringThe full XML data, stored in a string variable.
XPathStringXPath expression to extract data from the XML.
Note : XPath is a w3 standard language for addressing parts of an XML document. For more details see www.w3.org/TR/xpath

Common Errors

"NCN Names NCNames cannot start with the characters XX" 

XML Headers cannot start with numbers, so an error like this means somewhere within the JSON there is a key value that starts with a number, or an invalid character.  In the below JSON, we can see a key that starts with the number 9. This cannot be converted to XML, so the invalid character(s) need to be removed and replaced before xmlToItems() can be performed. 


Code Block
"flags_options": {
"9": {
"trusted": true
}
},
"trusted": true


...


Code Block
replaceAll($cleanJSON,'"\\d+":','"number":')


See Regular Expressions

Examples

If we add some xml into a $-variable:

Code Block
do(
   $xml = 
   '<?xml version="1.0" encoding="ISO-8859-1"?><store><thing category="X1"><name>Item1</name><price>15.00</price></thing><thing category="X2"><name>Item2</name><price>17.99</price></thing></store>',

   xmlToItems($xml, "/store/thing/price")

)

/* 
 * Where the xml would expanded would look like the below:
 *
   '<?xml version="1.0" encoding="ISO-8859-1"?>
   <store>
      <thing category="X1">
         <name>Item1</name>
         <price>15.00</price>
      </thing>
      <thing category="X2">
         <name>Item2</name>
         <price>17.99</price>
      </thing>
   </store>"',
 *
  xmlToItems($xml, "/store/thing/price")

)*/

Returns the values (in a list):

...