Last active
March 4, 2026 13:19
-
-
Save dzmitry-savitski/5658699aa1ae60d028afda0b709ea32b to your computer and use it in GitHub Desktop.
Revisions
-
dzmitry-savitski revised this gist
Mar 4, 2026 . No changes.There are no files selected for viewing
-
dzmitry-savitski revised this gist
Mar 4, 2026 . 1 changed file with 14 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,19 @@ const xmlToObject = (xml) => { const obj = {}; // children Array.from(xml.*).forEach(child => { const name = child.name().toString(); obj[name] = child.hasSimpleContent() ? child.toString() : xmlToObject(child); }); // attributes Array.from(xml.@*).forEach(attr => { obj[`@${attr.name()}`] = attr.toString(); }); return obj; }; -
dzmitry-savitski revised this gist
Mar 4, 2026 . 1 changed file with 13 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,11 @@ const xmlToObject = (xmlNode) => { const obj = {}; // iterate child elements const children = xmlNode.*; for (let i = 0; i < children.length(); i++) { const child = children[i]; const name = child.name().toString(); if (child.hasSimpleContent()) { obj[name] = child.toString(); @@ -11,14 +14,12 @@ function xmlToObject(xml) { } } // attributes const attrs = xmlNode.@*; for (let i = 0; i < attrs.length(); i++) { const attr = attrs[i]; obj[`@${attr.name()}`] = attr.toString(); } return obj; }; -
dzmitry-savitski created this gist
Mar 4, 2026 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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));