# rdfxml-streaming-parser

> Streaming RDF/XML parser

Latest version **3.3.0** (published 2026-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdfxml-streaming-parser
pnpm add rdfxml-streaming-parser
yarn add rdfxml-streaming-parser
bun add rdfxml-streaming-parser
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.3.0 |
| Published | 2026-08-13 |
| First published | 2018-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 119.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Ruben Taelman |
| Maintainers | rubensworks |
| Keywords | rdf/xml, streaming, parser, xml, rdfjs, rdf, linked data |

## Links

- npm: https://www.npmjs.com/package/rdfxml-streaming-parser
- Repository: https://github.com/rdfjs/rdfxml-streaming-parser.js
- Homepage: https://github.com/rdfjs/rdfxml-streaming-parser.js#readme
- Issues: https://github.com/rdfjs/rdfxml-streaming-parser.js/issues
- Funding: https://github.com/sponsors/rubensworks/
- npm.io page: https://npm.io/package/rdfxml-streaming-parser

## Dependencies (7)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [validate-iri](https://npm.io/package/validate-iri.md) ^1.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^4.4.2
- [rdf-data-factory](https://npm.io/package/rdf-data-factory.md) ^2.0.2
- [@rubensworks/saxes](https://npm.io/package/@rubensworks/saxes.md) ^6.0.1
- [@types/readable-stream](https://npm.io/package/@types/readable-stream.md) ^4.0.18
- [relative-to-absolute-iri](https://npm.io/package/relative-to-absolute-iri.md) ^1.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.3.0 (latest) — 2026-08-13
- 3.2.0 — 2025-11-03
- 3.1.0 — 2025-07-01
- 3.0.1 — 2025-01-08
- 3.0.0 — 2025-01-08
- 2.4.0 — 2023-11-24
- 2.3.0 — 2023-11-07
- 2.2.3 — 2023-06-05
- 2.2.2 — 2023-04-06
- 2.2.1 — 2022-11-09
- 2.2.0 — 2022-08-16
- 2.1.0 — 2022-07-27
- 2.0.0 — 2022-07-14
- 1.5.0 — 2021-08-11
- 1.4.0 — 2020-09-15
- … 15 more at https://npm.io/package/rdfxml-streaming-parser/versions

## README

# RDF/XML Streaming Parser

[![Build status](https://github.com/rdfjs/rdfxml-streaming-parser.js/workflows/CI/badge.svg)](https://github.com/rdfjs/rdfxml-streaming-parser.js/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/rdfjs/rdfxml-streaming-parser.js/badge.svg?branch=master)](https://coveralls.io/github/rdfjs/rdfxml-streaming-parser.js?branch=master)
[![npm version](https://badge.fury.io/js/rdfxml-streaming-parser.svg)](https://www.npmjs.com/package/rdfxml-streaming-parser)

A [fast](https://gist.github.com/rubensworks/a351f394ca6b70d6ad4ec1adc691a453), _streaming_ [RDF/XML 1.2](https://www.w3.org/TR/rdf12-xml/) parser
that outputs [RDFJS](http://rdf.js.org/)-compliant quads.

## Installation

```bash
$ yarn install rdfxml-streaming-parser
```

This package also works out-of-the-box in browsers via tools such as [webpack](https://webpack.js.org/) and [browserify](http://browserify.org/).

## Require

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

_or_

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

## Usage

`RdfXmlParser` is a Node [Transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform)
that takes in chunks of RDF/XML data,
and outputs [RDFJS](http://rdf.js.org/)-compliant quads.

It can be used to [`pipe`](https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options) streams to,
or you can write strings into the parser directly.

### Print all parsed triples from a file to the console

```javascript
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!'));
```

### Read all version attribute values

```javascript
const myParser = new RdfXmlParser();

fs.createReadStream('myfile.rdf')
  .pipe(myParser)
  .on('data', console.log)
  .on('version', console.log) // Log rdf:version attribute values
  .on('error', console.error)
  .on('end', () => console.log('All triples were parsed!'));
```

The error thrown for unsupported versions can be skipped
by setting `parseUnsupportedVersions` to `true` when constructing the parser.

### Manually write strings to the parser

```javascript
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](https://rdf.js.org/#sink-interface),
which makes it possible to alternatively parse streams using the `import` method.

```javascript
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](http://rdf.js.org/#datafactory-interface) to construct terms and triples. _(Default: `require('@rdfjs/data-model')`)_
* `baseIRI`: An initial default base IRI. _(Default: `''`)_
* `defaultGraph`: The default graph for constructing [quads](http://rdf.js.org/#dom-datafactory-quad). _(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](https://www.w3.org/TR/rdf-syntax-grammar/#section-Syntax-ID-xml-base). 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](https://github.com/comunica/validate-iri.js/).  _(Default: `IriValidationStrategy.Pragmatic`)_
* `parseUnsupportedVersions`: If no error should be emitted on unsupported versions. _(Default: `false`)_
* `version`: The version that was supplied as a media type parameter. _(Default: `undefined`)_
* `includeXmlNamespacesInLiterals`: If namespaces from the current and parent tags should be included in XML Literals. _(Default: `false`)_

```javascript
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,
    parseUnsupportedVersions: false,
    includeXmlNamespacesInLiterals: false,
});
```

## License
This software is written by [Ruben Taelman](http://rubensworks.net/).

This code is released under the [MIT license](http://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/rdfxml-streaming-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
