
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
sparqlxml-parse
Advanced tools
A utility package that allows you to parse SPARQL XML results in a convenient RDF/JS-based datastructure.
For example, the following SPARQL XML result can be converted as follows:
In:
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="book"/>
</head>
<results>
<result>
<binding name="book">
<uri>http://example.org/book/book1</uri>
</binding>
</result>
<result>
<binding name="book">
<uri>http://example.org/book/book2</uri>
</binding>
</result>
<result>
<binding name="book">
<uri>http://example.org/book/book3</uri>
</binding>
</result>
<result>
<binding name="book">
<uri>http://example.org/book/book4</uri>
</binding>
</result>
<result>
<binding name="book">
<uri>http://example.org/book/book5</uri>
</binding>
</result>
<result>
<binding name="book">
<triple>
<subject>
<uri>http://example.org/bob</uri>
</subject>
<predicate>
<uri>http://example.org/name</uri>
</predicate>
<object>
<literal datatype='http://example.org/Type'>Bob</literal>
</object>
</triple>
</binding>
</result>
</results>
</sparql>
Out:
[
{ '?book': namedNode('http://example.org/book/book1') },
{ '?book': namedNode('http://example.org/book/book2') },
{ '?book': namedNode('http://example.org/book/book3') },
{ '?book': namedNode('http://example.org/book/book4') },
{ '?book': namedNode('http://example.org/book/book5') },
{ '?book': quad(namedNode('http://example.org/bob'), namedNode('http://example.org/name'), literal('Bob', namedNode('http://example.org/Type'))) },
]
Where namedNode
is an RDF/JS named node, quad
is an RDF/JS quad/triple, and literal
is an RDF/JS literal.
This library automatically converts all SPARQL XML result values to their respective RDFJS type.
import {SparqlXmlParser} from "sparqlxml-parse";
const sparqlXmlParser = new SparqlXmlParser();
Optionally, you can provide a settings object to the constructor with optional parameters:
const sparqlXmlParser = new SparqlXmlParser({
dataFactory: dataFactory, // A custom RDFJS datafactory
prefixVariableQuestionMark: true, // If variable names in the output should be prefixed with '?', default is false.
});
If you have many query results, then a streaming-based approach
as provided by sparqlXmlParser.parseXmlResultsStream
is ideal.
const sparqlJsonResponseStream = streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="book"/>
</head>
<results>
<result>
<binding name="book">
<uri>http://example.org/book/book1</uri>
</binding>
</result>
</results>
</sparql>`);
sparqlXmlParser.parseXmlResultsStream(sparqlJsonResponseStream)
.on('data', (bindings: IBindings) => console.log(bindings));
// This will output [ { '?book': namedNode('http://example.org/book/book1') } ]
Optionally, you can also retrieve the variables inside the head
as follows by listening to the variables
event:
sparqlXmlParser.parseXmlResultsStream(sparqlJsonResponseStream)
.on('variables', (variables: RDF.Variable[]) => console.log(variables))
.on('data', (bindings: IBindings) => { return; });
// This will output [ variable('book') ]
const sparqlJsonResponseStream = streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<boolean>true</boolean>
</sparql>`);
sparqlXmlParser.parseXmlBooleanStream(sparqlJsonResponseStream)
.then((result: boolean) => console.log(result));
// This will output true
This software is written by Ruben Taelman.
This code is released under the MIT license.
v3.0.0 - 2025-01-08
<a name="v2.1.1"></a>
FAQs
Parses SPARQL XML query results
The npm package sparqlxml-parse receives a total of 8,612 weekly downloads. As such, sparqlxml-parse popularity was classified as popular.
We found that sparqlxml-parse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.