Created
September 21, 2012 15:22
-
-
Save jarrodbell/3762140 to your computer and use it in GitHub Desktop.
CommandFusion XML Parsing - JavaScript API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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