NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.43k stars 297 forks source link

Validation of multiple root elements #617

Open bendrissou opened 9 months ago

bendrissou commented 9 months ago

Description

The parser accepts inputs that have multiple XML root nodes, without raising an error. This is despite enabling the validator option "-v".

An XML document is expected to have one root element.

Input

<abc/><abc/>

There are two elements at the root level, 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

{ abc: [ '', '' ] }

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