I have an xml document with an & in it, so I am getting an error
[Error: Invalid character in entity name
Line: 155
Column: 63
Char: ]
I wrote a function to escape illegal xml characters:
const escapeIllegalCharacters = (xml) => {
xml = xml
.replace(/&/g,'&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/>/g, '>')
.replace(/</g, '<');
return (xml);
}
And put it into a valueProcessor:
return parse.parseString(xml, {valueProcessors: [escapeIllegalCharacters]});
But I'm still getting the same error. Is this the wrong way to escape characters using the xml2js module?