xml-js
xml-js copied to clipboard
Invalid character in entity name
I am getting an error when parsing a valid XML document:
Error: Invalid character in entity name
Line: 2
Column: 10124
Char:
at error (C:\Users\sean.mcilvenna\Code\FHIR.js\node_modules\sax\lib\sax.js:651:10)
at strictFail (C:\Users\sean.mcilvenna\Code\FHIR.js\node_modules\sax\lib\sax.js:677:7)
at SAXParser.write (C:\Users\sean.mcilvenna\Code\FHIR.js\node_modules\sax\lib\sax.js:1491:13)
at Object.module.exports [as xml2js] (C:\Users\sean.mcilvenna\Code\FHIR.js\node_modules\xml-js\lib\xml2js.js:337:12)
The problem appears to be coming from the & in the following XML snippet:
<mapping>
<identity value="rim"/>
<map value="status Amended & Final are differentiated by whether it is the subject of a ControlAct event with a type of "revise""/>
</mapping>
However, this snippet is valid XML... Can you confirm that this is indeed a bug?
Same thing I wanted to write it donw
xml = '<a wh="as&d@{*as">what</a>'
var result1 = convert.xml2json(
xml, {
compact: true,
spaces: 4,
ignoreAttributes: true,
attributeValueFn: (attrValue) => entities.encodeXML(attrValue)
});
I have the same problem when parsing a Vue Component:
<template><hr v-if="config && config.var === 'val'" /></template>
Hi @nashwaan, any comment on this, or #80?
It looks like if XML includes &
then xml-js
is searching for ;
and is testing everything between.
Problem is https://github.com/isaacs/sax-js
if (isNaN(num) || numStr.toLowerCase() !== entity) {
strictFail(parser, 'Invalid character entity')
return '&' + parser.entity + ';'
}
or better true
strict mode in xml2js.js
(strict - Boolean. Whether or not to be a jerk. Default: false.)
var parser = pureJsParser ? sax.parser(true, {}) : parser = new expat.Parser('UTF-8');
Result:
/node_modules/sax/lib/sax.js:968
throw this.error
^
Error: Invalid character entity
=>
var parser = pureJsParser ? sax.parser(false, {}) : parser = new expat.Parser('UTF-8');
Result:
OK!
I think there should be an option to enable/disable this "strict mode".
@nashwaan We really need to have an option how to change true
to false
.
anyone working on this?
I would like to know the same :)
Was this ever solved?
Not to my knowledge.
CC: @nashwaan
Alternatives, please!!!
Was this ever solved?
https://stackoverflow.com/questions/24877085/invalid-character-entity-parsing-xml
I used this answer and it worked