Skip to content

Instantly share code, notes, and snippets.

@ronaldroe
Last active August 17, 2020 20:08
Show Gist options
  • Save ronaldroe/47508d32ae6226acffb1a4d2e4fe1b49 to your computer and use it in GitHub Desktop.
Save ronaldroe/47508d32ae6226acffb1a4d2e4fe1b49 to your computer and use it in GitHub Desktop.
const XML2JSON = (xml, selector) => {
let entries = xml.querySelectorAll(selector);
let outData = [];
Array.from(entries).forEach((entry, i) => {
outData[i] = {};
Array.from(entry.children).forEach(node => {
let the_JSON = node.innerHTML;
if (the_JSON.length > 0) {
outData[i][node.localName] = JSON.parse(the_JSON);
}
});
});
return outData;
};
let myJSON = XML2JSON(new DOMParser().parseFromString(inputXML, "text/xml"), "entry content properties");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment