Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rdfxml-streaming-parser

rdfjs369.1kMIT3.0.1TypeScript support: included

Streaming RDF/XML parser

rdf/xml, streaming, parser, xml, rdfjs, rdf, linked data

readme

RDF/XML Streaming Parser

Build status Coverage Status npm version

A fast, streaming RDF/XML parser that outputs RDFJS-compliant quads.

Installation

$ yarn install rdfxml-streaming-parser

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Require

import {RdfXmlParser} from "rdfxml-streaming-parser";

or

const RdfXmlParser = require("rdfxml-streaming-parser").RdfXmlParser;

Usage

RdfXmlParser is a Node Transform stream that takes in chunks of RDF/XML data, and outputs RDFJS-compliant quads.

It can be used to pipe streams to, or you can write strings into the parser directly.

const myParser = new RdfXmlParser();

fs.createReadStream('myfile.rdf')
  .pipe(myParser)
  .on('data', console.log)
  .on('error', console.error)
  .on('end', () => console.log('All triples were parsed!'));

Manually write strings to the parser

const myParser = new RdfXmlParser();

myParser
  .on('data', console.log)
  .on('error', console.error)
  .on('end', () => console.log('All triples were parsed!'));

myParser.write('<?xml version="1.0"?>');
myParser.write(`<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/">`);
myParser.write(`<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">`);
myParser.write(`<ex:prop />`);
myParser.write(`</rdf:Description>`);
myParser.write(`</rdf:RDF>`);
myParser.end();

Import streams

This parser implements the RDFJS Sink interface, which makes it possible to alternatively parse streams using the import method.

const myParser = new RdfXmlParser();

const myTextStream = fs.createReadStream('myfile.rdf');

myParser.import(myTextStream)
  .on('data', console.log)
  .on('error', console.error)
  .on('end', () => console.log('All triples were parsed!'));

Configuration

Optionally, the following parameters can be set in the RdfXmlParser constructor:

  • dataFactory: A custom RDFJS DataFactory to construct terms and triples. (Default: require('@rdfjs/data-model'))
  • baseIRI: An initial default base IRI. (Default: '')
  • defaultGraph: The default graph for constructing quads. (Default: defaultGraph())
  • strict: If the internal SAX parser should parse XML in strict mode, and error if it is invalid. (Default: false)
  • trackPosition: If the internal position (line, column) should be tracked an emitted in error messages. (Default: false)
  • allowDuplicateRdfIds: By default multiple occurrences of the same rdf:ID value are not allowed. By setting this option to true, this uniqueness check can be disabled. (Default: false)
  • validateUri: By default, the parser validates each URI. (Default: true)
  • iriValidationStrategy: Allows to customize the used IRI validation strategy using the IriValidationStrategy enumeration. IRI validation is handled by validate-iri.js. (Default: IriValidationStrategy.Pragmatic)
new RdfXmlParser({
  dataFactory: require('@rdfjs/data-model'),
  baseIRI: 'http://example.org/',
  defaultGraph: namedNode('http://example.org/graph'),
  strict: true,
  trackPosition: true,
  allowDuplicateRdfIds: true,
  validateUri: true,
});

License

This software is written by Ruben Taelman.

This code is released under the MIT license.

changelog

Changelog

All notable changes to this project will be documented in this file.

v3.0.1 - 2025-01-08

Changed

v3.0.0 - 2025-01-08

BREAKING CHANGES

v2.4.0 - 2023-11-24

Added

v2.3.0 - 2023-11-07

Added

v2.2.3 - 2023-06-05

Fixed

v2.2.2 - 2023-04-06

Fixed

v2.2.1 - 2022-11-09

Fixed

v2.2.0 - 2022-08-16

Changed

v2.1.0 - 2022-07-27

Added

v2.0.0 - 2022-07-14

This release has been marked as a major change due to the transition from Node's internal stream API to readable-stream. Most users should experience not breakages with this change.

Changed

v1.5.0 - 2021-08-11

Changed

v1.4.0 - 2020-09-15

Changed

Fixed

v1.3.6 - 2020-06-03

Fixed

Changed

v1.3.5 - 2020-04-14

Fixed

v1.3.4 - 2020-01-27

Changed

v1.3.3 - 2020-01-17

Fixed

v1.3.2 - 2020-01-12

Fixed

v1.3.1 - 2019-07-17

Fixed

v1.3.0 - 2019-07-03

Added

Fixed

v1.2.4 - 2019-06-24

Fixed

v1.2.3 - 2019-04-25

Fixed

v1.2.2 - 2019-04-25

Fixed

v1.2.1 - 2019-04-02

Fixed

v1.2.0 - 2019-01-28

Added

v1.1.0 - 2018-11-08

Changed

v1.0.1 - 2018-10-09

Fixed

[1.0.0] - 2018-09-04

  • Initial release