Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sparqlxml-parse

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparqlxml-parse - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

6

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
<a name="1.1.0"></a>
## [1.1.0] - 2018-08-23
- [Update to pure-js sax-stream XML parser](https://github.com/rubensworks/sparqlxml-parse.js/commit/c231ff4045c8c0fddaa5c95f594dc801ee5e1cae)
<a name="1.0.0"></a>
## [1.0.0] - 2018-08-211
## [1.0.0] - 2018-08-21
- [Add SparqlXmlParser](https://github.com/rubensworks/sparqlxml-parse.js/commit/b15c0109a133144dccd8296756cb73a95ada5893)

58

lib/SparqlXmlParser.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DefaultDataFactory = require("@rdfjs/data-model");
const stream_1 = require("stream");
const SparqlXmlBindingsTransformer_1 = require("./SparqlXmlBindingsTransformer");
// tslint:disable-next-line:no-var-requires
const XmlStream = require('xml-stream');
const XmlNode = require('sax-stream');
/**

@@ -28,15 +27,15 @@ * Parser for the SPARQL Query Results XML format.

parseXmlResultsStream(sparqlResponseStream) {
// Collect variables
const variables = [];
const rawResultStream = new stream_1.Readable({ objectMode: true });
rawResultStream._read = () => { return; };
const xmlParser = new XmlStream(sparqlResponseStream);
xmlParser.collect('binding', true);
xmlParser.on('error', (error) => resultStream.emit('error', error));
xmlParser.on('endElement: head > variable', (node) => variables.push(this.dataFactory.variable(node.$.name)));
xmlParser.on('endElement: results result', (bindings) => rawResultStream.push(bindings));
xmlParser.on('end', () => {
resultStream.emit('variables', variables);
rawResultStream.push(null);
});
const resultStream = rawResultStream.pipe(new SparqlXmlBindingsTransformer_1.SparqlXmlBindingsTransformer(this));
sparqlResponseStream
.pipe(XmlNode({ strict: true, tag: 'variable' }))
.on('data', (node) => variables.push(this.dataFactory.variable(node.attribs.name)))
.on('error', () => { return; }) // Ignore errors, they will emitted in the results
.on('finish', () => resultStream.emit('variables', variables));
// Collect results
const resultStream = sparqlResponseStream
.pipe(XmlNode({ strict: true, tag: 'result' }))
.on('error', (error) => resultStream.emit('error', error))
.pipe(new SparqlXmlBindingsTransformer_1.SparqlXmlBindingsTransformer(this));
// Propagate errors
sparqlResponseStream.on('error', (error) => resultStream.emit('error', error));

@@ -52,21 +51,21 @@ return resultStream;

const bindings = {};
for (const binding of rawBindings.binding) {
const key = binding.$.name;
for (const binding of rawBindings.children.binding) {
const key = binding.attribs.name;
let value = null;
if (binding.bnode) {
value = this.dataFactory.blankNode(binding.bnode);
if (binding.children.bnode) {
value = this.dataFactory.blankNode(binding.children.bnode.value);
}
else if (binding.literal) {
if (binding.literal.$ && binding.literal.$['xml:lang']) {
value = this.dataFactory.literal(binding.literal.$text, binding.literal.$['xml:lang']);
else if (binding.children.literal) {
if (binding.children.literal.attribs && binding.children.literal.attribs['xml:lang']) {
value = this.dataFactory.literal(binding.children.literal.value, binding.children.literal.attribs['xml:lang']);
}
else if (binding.literal.$ && binding.literal.$.datatype) {
value = this.dataFactory.literal(binding.literal.$text, this.dataFactory.namedNode(binding.literal.$.datatype));
else if (binding.children.literal.attribs && binding.children.literal.attribs.datatype) {
value = this.dataFactory.literal(binding.children.literal.value, this.dataFactory.namedNode(binding.children.literal.attribs.datatype));
}
else {
value = this.dataFactory.literal(binding.literal);
value = this.dataFactory.literal(binding.children.literal.value);
}
}
else {
value = this.dataFactory.namedNode(binding.uri);
value = this.dataFactory.namedNode(binding.children.uri.value);
}

@@ -86,6 +85,7 @@ bindings[this.prefixVariableQuestionMark ? ('?' + key) : key] = value;

sparqlResponseStream.on('error', reject);
const xmlParser = new XmlStream(sparqlResponseStream);
xmlParser.on('error', reject);
xmlParser.on('endElement: boolean', (node) => resolve(node.$text === 'true'));
xmlParser.on('end', () => reject(new Error('No valid ASK response was found.')));
sparqlResponseStream
.pipe(XmlNode({ strict: true, tag: 'boolean' }))
.on('error', reject)
.on('data', (node) => resolve(node.value === 'true'))
.on('end', () => reject(new Error('No valid ASK response was found.')));
});

@@ -92,0 +92,0 @@ }

{
"name": "sparqlxml-parse",
"version": "1.0.0",
"version": "1.1.0",
"description": "Parses SPARQL XML query results",

@@ -74,4 +74,4 @@ "keywords": [

"@rdfjs/data-model": "^1.1.0",
"xml-stream": "^0.4.5"
"sax-stream": "^1.2.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc