{"library":"node-xml-stream-parser","title":"Node XML Stream Parser","description":"node-xml-stream-parser (current version 1.0.12) is a lightweight, fast XML/HTML stream parser designed for Node.js environments. It specializes in processing streaming XML, making it particularly suitable for tasks like parsing RSS, ATOM, or RDF feeds efficiently. The library's focus is on simplicity and performance, emitting events for `opentag`, `closetag`, `text`, `cdata`, and `instruction` as it processes the stream. It differentiates itself from more heavy-weight parsers (like `node-sax`) by offering a streamlined API and intentionally omitting support for less common XML features like comments, DOCTYPES, and ENTITY declarations, optimizing for speed and minimal overhead. It has seen consistent, though not rapid, updates, with the latest publish around 6 years ago on NPM, but GitHub activity suggests some more recent minor updates, making it a `maintenance` status.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install node-xml-stream-parser"],"cli":null},"imports":["import Parser from 'node-xml-stream-parser';","parser.on('opentag', (name, attrs) => { /* ... */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createReadStream } from 'fs';\nimport Parser from 'node-xml-stream-parser';\n\nconst xmlString = '<root><item attr=\"value\">Hello</item><![CDATA[Some Cdata]]><item/></root>';\n\nconst parser = new Parser();\n\nparser.on('opentag', (name, attrs) => {\n  console.log(`Open Tag: ${name}, Attributes:`, attrs);\n});\n\nparser.on('closetag', name => {\n  console.log(`Close Tag: ${name}`);\n});\n\nparser.on('text', text => {\n  if (text.trim() !== '') {\n    console.log(`Text: '${text.trim()}'`);\n  }\n});\n\nparser.on('cdata', cdata => {\n  console.log(`CDATA: '${cdata}'`);\n});\n\nparser.on('error', err => {\n  console.error('Parsing Error:', err.message);\n});\n\nparser.on('finish', () => {\n  console.log('XML stream parsing finished.');\n});\n\n// Option 1: Write data directly\nconsole.log('--- Parsing from string ---');\nparser.write(xmlString);\nparser.end();\n\n// Option 2: Pipe a file stream (for larger files)\n// Ensure 'feed.atom' exists with valid XML content for this part to run.\n// For example, create a dummy feed.atom: <feed><entry><title>Test</title></entry></feed>\nconst filePath = './feed.atom';\nconsole.log(`\\n--- Piping from file: ${filePath} ---`);\n// Create a dummy file for demonstration\nimport { writeFileSync } from 'fs';\nwriteFileSync(filePath, '<feed><entry><title>Hello World</title><content>Some content.</content></entry></feed>');\n\nconst fileStreamParser = new Parser();\nfileStreamParser.on('opentag', (name) => console.log(`[File] Open Tag: ${name}`));\nfileStreamParser.on('closetag', (name) => console.log(`[File] Close Tag: ${name}`));\nfileStreamParser.on('text', (text) => { if (text.trim() !== '') console.log(`[File] Text: '${text.trim()}'`); });\nfileStreamParser.on('error', (err) => console.error('[File] Error:', err.message));\nfileStreamParser.on('finish', () => console.log('[File] Parsing from file finished.'));\n\ncreateReadStream(filePath).pipe(fileStreamParser);","lang":"javascript","description":"This quickstart demonstrates how to instantiate the XML stream parser, register event listeners for various XML node types (open/close tags, text, CDATA), handle errors, and detect the stream's completion. It includes examples for both directly writing XML strings and piping from a file stream.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}