// the find
isaacs/sax-js
A sax style parser for JS
A SAX-style streaming XML parser for JavaScript, written by Isaac Schlueter (npm's creator). It handles a strict mode for well-formed XML and a loose mode for the kind of broken XML you find in RSS feeds and legacy APIs. Zero dependencies, works in Node and browsers.
The loose/strict mode split is genuinely useful — strict mode enforces well-formedness, loose mode just gets through the document, which is exactly what you want for RSS and Atom feeds that technically fail the spec. The streaming write() interface means you can feed it chunks as they arrive without buffering the whole document. The test suite is thorough and honest: there are explicit tests for billion-laughs, buffer overrun, and recursive entities, so the security corner cases have been thought about. Namespace support is opt-in via the xmlns option rather than always-on overhead.
The entire library is a single 1600-line file (lib/sax.js) with no internal structure — reading the parser state machine is not pleasant. It predates modern JavaScript and uses the old onX assignment pattern instead of EventEmitter throughout, which means you can only have one listener per event. DTD and entity declaration parsing is explicitly punted: custom entities in DOCTYPE are your problem, which will bite you with any non-trivial XML that isn't XHTML or RSS. It hasn't had a real release since 2017 (last npm publish is 1.2.4); the repo is active on GitHub but the package is stale, so you're either pinning an old version or pulling from git.