xml-reader is a lightweight and performant XML parser designed for both Node.js and browser environments, including modern platforms like React Native, ServiceWorkers, and WebWorkers. Currently at stable version 2.4.3, the library focuses on providing a simple, event-driven, and synchronous API for parsing XML documents. It supports incremental processing, allowing for efficient handling of large XML streams with low memory usage in its dedicated stream mode. While not a rapid release cycle, the project receives maintenance updates for bug fixes, such as the recent 2.4.3 patch for parent node references in text nodes. Its key differentiators include its small footprint, versatile environment compatibility, and the ability to process XML piece-by-piece, making it suitable for real-time or resource-constrained applications, particularly when combined with its companion `xml-query` package for data extraction.
npm install xml-readerVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing an XML string using the event-driven API and logging specific elements from the resulting JavaScript object structure.
When creating a reader instance, specify `XmlReader.create({ tagPrefix: '' })` to restore the previous behavior for tag-specific events.Ensure the XML string passed to `parseSync()` is a fully enclosed and valid XML document. For streaming or potentially incomplete XML, use the event-driven `parse()` method with a `stream: true` option.
If you need to access the full parsed tree after processing in stream mode, you must manually accumulate the emitted nodes or process them as they arrive via `tag:` events. The `done` event in stream mode is primarily an indication of parsing completion, not a return of the complete in-memory tree.
Upgrade to `xml-reader@2.4.3` or newer to ensure correct parent references, where text nodes do not have an extraneous `parent` property.
Instantiate the reader correctly: `const reader = XmlReader.create();` before using event listeners or parsing methods.
Ensure the XML input for `parseSync()` is a complete and valid document. For partial or streaming XML, use the event-driven `reader.parse()` method.
For ES modules, consider using `import * as XmlReader from 'xml-reader';` or configure your build system to transpile CommonJS to ESM. Alternatively, ensure your file is treated as a CommonJS module.
No dependency data recorded yet.