Created
May 13, 2022 13:25
-
-
Save JohnMarkT/b9f4ed8dc123f852c305124f088d39fb to your computer and use it in GitHub Desktop.
Parse XML string
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 parseXML = (xmlStr) => { | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(xmlStr, 'application/xml'); | |
const errorNode = doc.querySelector('parsererror'); | |
if (errorNode) { | |
console.log('error while parsing'); | |
return errorNode; | |
} else { | |
console.log('parsing complete: ' + doc.documentElement.nodeName); | |
return doc; | |
} | |
}; | |
export default { | |
parseXML | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment