Registry / data / rdfxml-streaming-parser

rdfxml-streaming-parser

JSON →
library3.2.0jsnpmunverified

rdfxml-streaming-parser is a JavaScript library designed for efficient, streaming parsing of RDF/XML documents into RDFJS-compliant quads. Currently at version 3.2.0, it maintains an active release schedule with minor updates. Its core functionality revolves around acting as a Node.js Transform stream, allowing developers to pipe data streams directly or feed XML string chunks manually. This streaming approach is a key differentiator, enabling the processing of large RDF/XML datasets without requiring the entire document to be loaded into memory. The library also integrates with the broader RDF.js ecosystem by implementing the Sink interface, providing flexibility in how streams are consumed. It ships with comprehensive TypeScript types and configurable options for data factory, base IRI, default graph, and XML parsing strictness.

npm install rdfxml-streaming-parser
INSTALL
IMPORT
SIG · RDFXML-STREAMING-P
R
rdfxml-streaming-parser
datajavascriptv3.2.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RdfXmlParser
✓ import { RdfXmlParser } from 'rdfxml-streaming-parser';
✗ import RdfXmlParser from 'rdfxml-streaming-parser';
RdfXmlParser is a named export, not a default export.
RdfXmlParser (CommonJS)
✓ const { RdfXmlParser } = require('rdfxml-streaming-parser');
✗ const RdfXmlParser = require('rdfxml-streaming-parser');
CommonJS `require` should destructure the named export RdfXmlParser.
RdfXmlParserOptions (TypeScript)
✓ import type { RdfXmlParserOptions } from 'rdfxml-streaming-parser';
Import types separately for type-only usage in TypeScript.

Demonstrates how to initialize RdfXmlParser, pipe a simulated data stream to it, and listen for 'data' (quads), 'version', 'error', and 'end' events to process the parsed RDF/XML.

import * as fs from 'fs'; import { RdfXmlParser } from 'rdfxml-streaming-parser'; // Create a new parser instance const myParser = new RdfXmlParser({ baseIRI: 'http://example.org/base/', // Optional: set an initial base IRI strict: false // Optional: allow non-strict XML parsing }); // Assuming 'example.rdf' is an RDF/XML file in the same directory // For a real-world scenario, you might fetch this from a URL or an upload. // Example content for 'example.rdf': // <?xml version="1.0"?> // <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" // xmlns:ex="http://example.org/stuff/1.0/" // xml:base="http://example.org/triples/"> // <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"> // <ex:prop>value</ex:prop> // </rdf:Description> // </rdf:RDF> const rdfXmlContent = `<?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/stuff/1.0/" xml:base="http://example.org/triples/"> <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"> <ex:prop>Some property value</ex:prop> </rdf:Description> <rdf:Description rdf:about="http://example.org/another"> <ex:name>Another resource</ex:name> </rdf:Description> </rdf:RDF>`; // For a runnable example, let's simulate a readable stream from a string // In a real app, you'd use fs.createReadStream or an HTTP response stream const { Readable } = require('stream'); const stringStream = Readable.from([rdfXmlContent]); stringStream .pipe(myParser) .on('data', (quad) => { // Each 'data' event emits an RDFJS Quad object console.log('Parsed Quad:', quad.toString()); }) .on('version', (version) => { // Optionally listen for rdf:version attributes console.log('RDF Version Attribute:', version); }) .on('error', (error) => { // Handle any parsing errors console.error('Parsing Error:', error); }) .on('end', () => { // Stream has finished parsing all data console.log('All RDF/XML data parsed successfully!'); });
Debug
Known issues
gotchaBy default, the parser throws an error if it encounters an unsupported RDF version attribute (e.g., 'rdf:version').
fix
To suppress this error and continue parsing, set the `parseUnsupportedVersions` option to `true` when constructing the parser: `new RdfXmlParser({ parseUnsupportedVersions: true })`.
affects: >=1.0.0
gotchaThe `strict` option enables strict XML parsing, which can cause the parser to error on valid but non-strict XML documents. Most RDF/XML in the wild might not adhere to strict XML rules.
fix
It is generally recommended to keep `strict: false` (the default) unless you specifically require strict XML validation. If set to `true`, ensure your input XML is strictly well-formed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Premature end of document
The input RDF/XML stream ended unexpectedly, or the document is malformed/incomplete.
fix
Ensure the input stream contains complete and well-formed RDF/XML. Check for truncated files or incomplete HTTP responses. Verify the XML structure manually or with an XML validator.
TypeError: Cannot read property 'pipe' of undefined
Attempting to call `.pipe()` on an object that is not a readable stream, or the stream source (e.g., `fs.createReadStream`) failed to return a stream.
fix
Verify that the object you are piping *from* is a valid Node.js Readable stream. For file operations, ensure the file path is correct and the file exists. For network requests, confirm the response object provides a readable stream.
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies
@rdfjs/data-modelrequiredProvides the default RDFJS DataFactory implementation for constructing terms and quads if not explicitly overridden.
Agent activity
6 hits · last 30 days
node
6
Resources
rdfxml-streaming-parser — npm install rdfxml-streaming-parser · libregistry