I am trying to create a list of Chapter Officers and their respective positions. The data comes from a series of XML key/value pairs accessed via web service (Key: Member_Name,
In Coldfusion 10 or Railo 4, you could use the Underscore.cfc library to help clean your solution up a lot:
soapBody = XmlParse(cfhttp.filecontent);
fields = xmlSearch(soapBody,"//*[local-name()='Fields']");
chapterOfficers = _.map(fields, function (field) {
var officer = {};
_.each(field.xmlChildren, function (KeyValueOfstringanyType) {
var key = KeyValueOfstringanyType['b:Key'].xmlText;
var value = KeyValueOfstringanyType['b:Value'].xmlText;
officer[key] = value;
});
return officer;
});
#officer.Member_Name#
#officer.Position_Name#
Now isn't that nicer? I'm not exactly sure what your SOAP response looks like, but you should be able to tweak the xmlSearch() to match on the parent element of KeyValueOfstringanyType. I also removed all the unnecessary cfoutputs for you. Also, I'd recommend switching to JSON instead of XML. It's a LOT easier to parse.
(Disclaimer: I wrote the Underscore.cfc library)