> parser.parse('Invalid XML!v>')
[]
> parser.parse('<Invalid XML')
Uncaught TypeError: Cannot read properties of undefined (reading 'tagName')
at OrderedObjParser.parseXml (/Users/renan/tmp/latest-react/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js:283:29)
at XMLParser.parse (/Users/renan/tmp/latest-react/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js:35:48)
You can see it's parsing Invalid XML!v> but it won't take <Invalid XML. If you use require('fast-xml-parser').XMLValidator.validate function, you see the former is indeed invalid.
> require('fast-xml-parser').XMLValidator.validate('Invalid XML!v>')
{
err: {
code: 'InvalidChar',
msg: "char 'I' is not expected.",
line: 1,
col: 1
}
}
I've been getting inconsistent validation, when trying to make
invalidXml
prop work. Certain constructs are taken to be valid while others aren't.For example,
Invalid XML!v>
is seen as valid while<Invalid XML
is not valid.I looked into how the library is doing the validation here:
https://github.com/alissonmbr/react-xml-viewer/blob/b47d385b2b63bb468903b6591bcf8966e25df669/src/hooks/useXMLViewer.ts#L18
And I tried using the same functions, see below.
Code example
You can see it's parsing
Invalid XML!v>
but it won't take<Invalid XML
. If you userequire('fast-xml-parser').XMLValidator.validate
function, you see the former is indeed invalid.