fast-xml-parser icon indicating copy to clipboard operation
fast-xml-parser copied to clipboard

Parsing an invalid XML element

Open bendrissou opened this issue 2 years ago • 1 comments

Description

The parser accepts and parses a XML element that is syntactically invalid, without raising an error. This is despite enabling the validator option "-v".

Input

<?xml version="1.0" ?>  <a/> <! <!---->  	

In the above example, token <! is duplicated, which I expected to raise an error. The input is saved in a file named example.xml.

Code

./src/cli/cli.js -v example.xml

Output

{ '?xml': { '@_version': 1 }, a: '', '!': '' }

My question is: Why the XML validator doesn't throw an error in this case? Please note that xmllint rejects the input example as invalid.

bendrissou avatar Oct 03 '23 09:10 bendrissou

Hi @amitguptagwl

I tried the above input from the code:

#!/usr/bin/env node
const {XMLValidator} = require("../fxp");
const result = XMLValidator.validate('<?xml version="1.0" ?>  <a/> <! <!---->', {
    allowBooleanAttributes: true
});
console.log(result);

Output is:

true

So, the XML input was accepted, despite being invalid.

bendrissou avatar Jun 10 '24 14:06 bendrissou