Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Created September 21, 2012 15:22
Show Gist options
  • Save jarrodbell/3762140 to your computer and use it in GitHub Desktop.
Save jarrodbell/3762140 to your computer and use it in GitHub Desktop.
CommandFusion XML Parsing - JavaScript API
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(body, 'text/xml');
// Get the data from XML
var results = xmlDoc.evaluate("//Item", xmlDoc, null, XPathResult.ANY_TYPE, null);
var infoItem = results.iterateNext();
while (infoItem) {
CF.log("Name Attribute: " + infoItem.getAttribute("Name"));
CF.log("Node Value: " + infoItem.childNodes[0].nodeValue);
infoItem = results.iterateNext();
}
// You can also get specific single items in the XML directly:
CF.log("Node value where its name attribute equals 'Test': " + xmlDoc.evaluate("//Item[@Name='Test']", xmlDoc, null, XPathResult.STRING_TYPE, null).stringValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment