microdata-rdf-streaming-parser is a JavaScript library designed for efficiently parsing HTML documents containing Microdata annotations and transforming them into RDFJS-compliant quads. Currently at version 3.0.0, the library prioritizes a streaming approach, allowing it to process documents larger than available memory and emit RDF triples as soon as possible, rather than waiting for the entire document to be loaded. It is 100% spec-compliant with the W3C Microdata to RDF transformation algorithm and integrates seamlessly with the RDFJS ecosystem for its data model representations. While a specific release cadence is not outlined, major version updates, like the current v3, typically introduce significant architectural changes, such as a shift towards ESM-first patterns. Its key differentiators include its robust streaming capability powered by `htmlparser2`, strict adherence to the Microdata to RDF specification, and its lightweight footprint, making it suitable for both Node.js environments and browser-based applications via bundlers.
npm install microdata-rdf-streaming-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the `MicrodataRdfParser` with custom options, feed it an HTML string via a readable stream, and log the resulting RDFJS quads as they are emitted in a streaming fashion.
Review the official documentation for any v3 migration guide. Update import statements to use ESM `import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser';` for modern Node.js and bundler environments. If using CommonJS, explicit `require` access (e.g., `require('pkg').Symbol`) might be needed, or consider migrating to ESM.Always provide a `baseIRI` option in the `MicrodataRdfParser` constructor that represents the absolute URL of the HTML document being parsed. This ensures correct URI resolution for Microdata properties.
If using a particular RDFJS implementation, pass its `DataFactory` instance to the `dataFactory` option (e.g., `dataFactory: myCustomDataFactory`). Ensure your RDFJS dependency aligns with the library's expectations.
Always attach an `'error'` listener to both your input `Readable` stream and the `MicrodataRdfParser` instance (e.g., `.on('error', console.error)`) to catch and gracefully handle any parsing or stream-related exceptions.Ensure you are using the correct `import` statement for your environment. For modern Node.js and bundlers, use `import { MicrodataRdfParser } from 'microdata-rdf-streaming-parser';`. If explicitly targeting CommonJS, ensure the package supports it with `const { MicrodataRdfParser } = require('microdata-rdf-streaming-parser');`.Verify that the stream you are piping into `MicrodataRdfParser` is a valid `Readable` stream and is still open. When parsing a string, use `Readable.from([yourString])` to wrap it in a readable stream.
Ensure HTML input is processed in reasonably sized chunks for optimal streaming performance, though for most valid documents, the streaming nature of `htmlparser2` should mitigate this. For unusually deep or complex documents, consider breaking them into smaller, more manageable pieces before feeding them to the parser, if possible.