Last active
August 17, 2020 20:08
-
-
Save ronaldroe/47508d32ae6226acffb1a4d2e4fe1b49 to your computer and use it in GitHub Desktop.
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
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