Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Last active January 12, 2024 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmaupin/eeab2b4dffab18f12a1b5f279e0dcb75 to your computer and use it in GitHub Desktop.
Save bmaupin/eeab2b4dffab18f12a1b5f279e0dcb75 to your computer and use it in GitHub Desktop.
JavaScript XML parsers
Parser Size Maintained Node.js Browser Streaming Types Modifying XML Notes
jsdom 3.11 MB yes yes N/A DefinitelyTyped yes Probably the best choice since its API is closest to the browser API for manipulating XML
cheerio 558 kB yes yes yes included yes jQuery-like API for parsing and manipulating HTML and XML
xmldoc 41.4 kB yes yes yes DefinitelyTyped Partial, not recommended (nfarina/xmldoc#51)
@xmldom/xmldom 182 kB yes yes yes included yes ⚠️ Based on DOM but no querySelector/querySelectorAll
sax 55 kB yes yes yes? yes DefinitelyTyped Not recommended ⚠️ API is callback-based and very cludgy, but it has streaming and is very fast
xml2js ⚠️ 3.44 MB yes yes yes no DefinitelyTyped
@xml-tools/parser 39 kB ⚠️ ??? yes included Automatic error recovery
fast-xml-parser 107 kB yes yes yes no included ⚠️ No streaming, ignores attributes by default, weird attribute access syntax (tag['@_attribute]']), some people have moved away from it (1, 2)
@rgrove/parse-xml 380 kB yes yes yes ⚠️ no included ⚠️ Crashes on 302 MB XML file
xml-stream ⚠??? ⚠️ no yes yes ⚠️ no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment