{"library":"saxes","title":"Saxes Streaming XML Parser","description":"Saxes is an evented, streaming XML parser for JavaScript, currently at version 6.0.0. It is a modern, stricter, and significantly faster fork of the original `sax` library, designed primarily for Node.js environments (requiring Node.js >=12.22.7) but also functional in browsers. Its core differentiator is a strong adherence to XML 1.0/1.1 and Namespaces in XML 1.0/1.1 well-formedness rules, unlike `sax` which tolerates malformed structures. This makes `saxes` unsuitable for HTML or pseudo-XML parsing, as it will explicitly report well-formedness errors. While it is a non-validating parser, it aims to catch all malformed constructs outside of thorough DTD validation. `saxes` does not include a `Stream` API, a notable departure from its `sax` predecessor, and its `onerror` handler defaults to throwing errors, which can be overridden. The project is actively maintained, with a focus on performance and strict conformance to XML specifications.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install saxes"],"cli":null},"imports":["import { SaxesParser } from 'saxes';","import type { SaxesOptions } from 'saxes';","const { SaxesParser } = require('saxes');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { SaxesParser } from 'saxes';\n\nconst xmlString = `<root>\n  <item id=\"1\">Hello &amp; World!</item>\n  <item id=\"2\"><![CDATA[<tag>content</tag>]]></item>\n</root>`;\n\nconst parser = new SaxesParser();\n\nparser.on('error', (err) => {\n  console.error('XML Parsing Error:', err.message);\n  // The default onerror handler throws, so subsequent data calls might not happen if not caught.\n});\n\nparser.on('opentag', (node) => {\n  console.log(`Opened tag: ${node.name} with attributes:`, node.attributes);\n});\n\nparser.on('text', (text) => {\n  if (text.trim().length > 0) {\n    console.log(`Text content: '${text.trim()}'`);\n  }\n});\n\nparser.on('closetag', (nodeName) => {\n  console.log(`Closed tag: ${nodeName}`);\n});\n\nparser.on('end', () => {\n  console.log('Finished parsing XML.');\n});\n\ntry {\n  parser.write(xmlString).close();\n} catch (e) {\n  // Catch errors if the default onerror handler is active and throws\n  console.error('Caught error during write/close:', e.message);\n}","lang":"typescript","description":"Demonstrates basic parsing of an XML string, handling open tags, text content, close tags, and errors using event listeners. It shows both attributes and CDATA sections.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}