isaacs / sax-js

A sax style parser for JS
Other
1.09k stars 325 forks source link

Multiple root elements, text in second root #246

Open kenjiuno opened 4 years ago

kenjiuno commented 4 years ago

sax-js can accept this:

<a></a>
<b></b>

But sax-js cannot accept this:

<a></a>
<b>X</b>
Error: Text data outside of root node.
Line: 1
Column: 4
Char: X
    at error (H:\Proj\xml-summary-cli\node_modules\sax\lib\sax.js:651:10)
    at strictFail (H:\Proj\xml-summary-cli\node_modules\sax\lib\sax.js:677:7)
    at SAXParser.write (H:\Proj\xml-summary-cli\node_modules\sax\lib\sax.js:1035:15)
    at SAXStream.write (H:\Proj\xml-summary-cli\node_modules\sax\lib\sax.js:239:18)
    at ReadStream.ondata (_stream_readable.js:693:20)
    at ReadStream.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at fs.read (internal/fs/streams.js:183:12)

I want to parse that document. Because Windows Update wsusscn2.cab contains such a multi-rooted XML document

~/wsusscn2/x/10000190:

<ExtendedProperties DefaultPropertiesLanguage="en" Handler="http://schemas.microsoft.com/msus/2002/12/UpdateHandlers/WindowsInstaller" MaxDownloadSize="475894" MinDownloadSize="0">
 <InstallationBehavior RebootBehavior="CanRequestReboot" />
 <UninstallationBehavior />
</ExtendedProperties>
<Files>
 <File Digest="2wKNw4a06wUuomQDSUv6LEKlLoA=" DigestAlgorithm="SHA1" FileName="convintl-sr-latn-cs.cab" Size="475894" Modified="2013-10-29T13:40:20Z" PatchingType="SelfContained">
  <AdditionalDigest Algorithm="SHA256">pR4dV0DWJ0T4bAZlBb5q+U81nY/pwaaaoc27UhpQIKw=</AdditionalDigest>
 </File>
</Files>
<HandlerSpecificData type="msp:WindowsInstaller">
 <MspData CommandLine="DISABLESRCPROMPT=1 LOCALCACHESRCRES=0 NOLOCALCACHEROLLBACK=1" UninstallCommandLine="DISABLESRCPROMPT=1 LOCALCACHESRCRES=0 NOLOCALCACHEROLLBACK=1" FullFilePatchCode="{a64c19ed-f339-42fc-8195-7d4570060f9a}" />
</HandlerSpecificData>