{"library":"saxen","title":"saxen: Super Fast SAX XML Parser","description":"Saxen is a minimalistic, high-performance SAX-style XML parser designed for JavaScript environments, primarily Node.js. It distinguishes itself by being extremely lightweight (around 2.6KB minified + gzipped) and fast, while offering essential features like optional namespace awareness and entity decoding. The current stable version is 11.0.2, with major versions introducing significant breaking changes, such as the transition to an ESM-only distribution in v11 and stricter Node.js version requirements. Its design prioritizes speed and small footprint, making it suitable for applications where parsing efficiency is critical, and a full DOM parser is unnecessary. Saxen provides a stream of events (`openTag`, `closeTag`, `text`, `error`, etc.) that developers can hook into to process XML data incrementally, and supports an optional \"proxy mode\" for richer element state at a minor performance cost. Unlike some other parsers, it explicitly eschews certain features to maintain its focus on core SAX parsing.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install saxen"],"cli":null},"imports":["import { Parser } from 'saxen';","import type { Parser } from 'saxen';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Parser } from 'saxen';\n\n// Instantiate the parser\nconst parser = new Parser();\n\n// Configure namespaces for consistent prefix handling\nparser.ns({\n  'http://foo': 'foo',\n  'http://bar': 'bar',\n  'http://baz': 'baz' \n});\n\n// Register event listeners for different XML parsing stages\nparser.on('openTag', function(elementName, attrGetter, decodeEntities, selfClosing, getContext) {\n  console.log(`Open Tag: ${elementName}, Self-closing: ${selfClosing}`);\n  const attrs = attrGetter();\n  console.log('Attributes:', attrs);\n  // Example of using contextGetter\n  const context = getContext();\n  console.log('Context (line/column):', context.line, context.column);\n});\n\nparser.on('closeTag', function(elementName, decodeEntities, selfClosing, getContext) {\n  console.log(`Close Tag: ${elementName}`);\n});\n\nparser.on('text', function(value, decodeEntities, getContext) {\n  if (value.trim().length > 0) {\n    console.log(`Text content: \"${value.trim()}\"`);\n  }\n});\n\nparser.on('error', function(err, contextGetter) {\n  console.error('Parsing error:', err.message, 'at', contextGetter().line, contextGetter().column);\n});\n\n// Parse an example XML string\nconst xmlString = `\n  <root xmlns=\"http://foo\" xmlns:bar=\"http://bar\" xmlns:baz=\"http://baz\" bar:id=\"123\">\n    <foo:child attr=\"value\">\n      Some text content.\n      <baz:nested />\n    </foo:child>\n    <!-- A comment -->\n  </root>\n`;\nconsole.log('Parsing XML...');\nparser.parse(xmlString);\nconsole.log('Parsing complete.');\n\n// Demonstrate proxy mode with its own parser instance\nconst proxyParser = new Parser({ proxy: true });\nproxyParser.ns({ 'http://proxy-ns': 'pxy' });\nproxyParser.on('openTag', function(el, decodeEntities, selfClosing, getContext) {\n  console.log(`[Proxy Mode] Open Tag: ${el.name} (original: ${el.originalName})`);\n  console.log(`[Proxy Mode] Attributes:`, el.attrs);\n});\nproxyParser.parse('<pxy:document xmlns:pxy=\"http://proxy-ns\" version=\"1.0\" />');","lang":"javascript","description":"Demonstrates basic usage of the `Parser` class, including event-based parsing, namespace configuration, handling various XML events, and an example of the optional proxy mode.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}