xml-to-json-stream
Version:
Simple module to convert XML to JSON with javascript
10 lines (7 loc) • 480 B
JavaScript
module.exports = function cleanXML(xml) {
return xml.replace(/>\s*</g, '><') //remove white spaces between elements
.replace(/<\?xml.*\?>/g, '') //remove the root element
.replace(/<!--.*-->/g,'') //remove comments
.replace(/>\s*/g, '>') // remove any white spaces at the end of the xml string if any
.replace(/\s*</g, '<') // remove any white spaces that are left at the beginning of the xml string
}