sparqlxml-parse
Advanced tools
Comparing version 1.0.0 to 1.1.0
# 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) |
"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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15307
+ Addedsax-stream@^1.2.3
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsax-stream@1.3.0(transitive)
- Removedxml-stream@^0.4.5
- Removedbindings@1.5.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removediconv@2.3.5(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removednan@2.22.0(transitive)
- Removednode-expat@2.4.1(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedxml-stream@0.4.5(transitive)