Skip to content

Instantly share code, notes, and snippets.

@dzmitry-savitski
Last active March 4, 2026 13:19
Show Gist options
  • Select an option

  • Save dzmitry-savitski/5658699aa1ae60d028afda0b709ea32b to your computer and use it in GitHub Desktop.

Select an option

Save dzmitry-savitski/5658699aa1ae60d028afda0b709ea32b to your computer and use it in GitHub Desktop.
XML to javascript
function xmlToObject(xml) {
var obj = {};
for each (var child in xml.*) {
var name = child.name().toString();
if (child.hasSimpleContent()) {
obj[name] = child.toString();
} else {
obj[name] = xmlToObject(child);
}
}
for each (var attr in xml.@*) {
obj["@" + attr.name()] = attr.toString();
}
return obj;
}
var xml = new XML(xmlString);
var result = xmlToObject(xml);
logger.info(JSON.stringify(result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment