Skip to content
Permalink
Browse files

Fix parsing error on single bindings

  • Loading branch information...
rubensworks committed Aug 24, 2018
1 parent 74787ad commit 79b5a5bcad0abd8080b3900e84ab4e956ad13940
Showing with 23 additions and 1 deletion.
  1. +3 −1 lib/SparqlXmlParser.ts
  2. +20 −0 test/SparqlXmlParser-test.ts
@@ -57,7 +57,9 @@ export class SparqlXmlParser {
*/
public parseXmlBindings(rawBindings: any): IBindings {
const bindings: IBindings = {};
for (const binding of rawBindings.children.binding) {
const bindingsArray = Array.isArray(rawBindings.children.binding)
? rawBindings.children.binding : [ rawBindings.children.binding ];
for (const binding of bindingsArray) {
const key = binding.attribs.name;
let value: RDF.Term = null;
if (binding.children.bnode) {
@@ -171,6 +171,26 @@ describe('SparqlXmlParser', () => {
]);
});

it('should convert a SPARQL XML response with a single binding', async () => {
return expect(await arrayifyStream(parser.parseXmlResultsStream(streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="x"/>
</head>
<results>
<result>
<binding name="x">
<bnode>r1</bnode>
</binding>
</result>
</results>
</sparql>
`))))
.toEqual([
{ '?x': blankNode('r1') },
]);
});

it('should convert a SPARQL XML response and emit the variables', async () => {
const stream = parser.parseXmlResultsStream(streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">

0 comments on commit 79b5a5b

Please sign in to comment.
You can’t perform that action at this time.