The `rdfa-streaming-parser` package provides a high-performance, lightweight, and 100% spec-compliant streaming parser for RDFa 1.1 data. It is currently at version 3.0.2. This library is designed to emit RDFJS-compliant quads as soon as possible, enabling the efficient parsing of documents larger than available memory. Its streaming nature leverages Node.js Transform streams, allowing for direct piping of input sources like file streams. It also implements the RDFJS Sink interface for alternative stream processing. Key differentiators include its strict adherence to the RDFa 1.1 specification, its low memory footprint due to streaming, and its compatibility with the RDFJS ecosystem for data representation. The release cadence appears stable, with major version 3 indicating significant updates from previous iterations.
npm install rdfa-streaming-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse an RDFa document from a file stream using `RdfaParser`, log the extracted RDFJS quads, and gracefully handle completion or errors. A temporary HTML file is created and then cleaned up.
Review the official changelog for `rdfa-streaming-parser` between your current version and `3.x` and update your code accordingly. Pay close attention to error handling and constructor options.
Always provide at least a `baseIRI` (e.g., `https://example.com/`) and/or `contentType` (e.g., `'text/html'`) when initializing `RdfaParser` to ensure proper parsing context.
Consider migrating CommonJS `require('rdfa-streaming-parser').RdfaParser` statements to `import { RdfaParser } from 'rdfa-streaming-parser';` for alignment with current JavaScript best practices.Verify compatibility with the RDFJS specification for any RDF processing libraries you are using. If needed, you can pass a custom `dataFactory` to the `RdfaParser` constructor to ensure consistency.
For CommonJS, use `const { RdfaParser } = require('rdfa-streaming-parser');` or `const RdfaParser = require('rdfa-streaming-parser').RdfaParser;`. For ESM, use `import { RdfaParser } from 'rdfa-streaming-parser';`.Provide a `baseIRI` and/or `contentType` (e.g., `'text/html'`) in the `RdfaParser` constructor options. Example: `new RdfaParser({ baseIRI: 'https://example.com/', contentType: 'text/html' });`.Either configure your project to use ES Modules (by adding `"type": "module"` to `package.json` and using `.js` files, or renaming to `.mjs`), or use CommonJS `require` syntax: `const { RdfaParser } = require('rdfa-streaming-parser');`.