Sean B. Durkin
Sean B. Durkin

Reputation: 12729

Iteration through a Saxon-JS sequence

This javascript (hosted on a browser console) ...

var xmlDoc = jQuery.parseXML("<foo>Stuff</foo>");
for (let item of SaxonJS.XPath.evaluate( '/foo/text()', xmlDoc,
                 {resultForm:'iterator'})) {console.log(item);}

... returns error ...

SaxonJS.XPath.evaluate(...) is not a function or its return value is not iterable

... instead of the expected output ...

"Stuff"

Why?

According to documentation here, the evaluate() expression should return an iterator. But it does not.

Libraries used include:

  1. jQuery; and
  2. Saxon-js javascript library.

Update

I can get a functionally correct result with this alternative expression ...

for (let item of SaxonJS.XPath.evaluate('string(foo/text())',xmlDoc, 
  {resultForm:'array'})) {console.log(item)}

... but I really want to use a lazy iterator, if that is possible, rather than an array.

Upvotes: 0

Views: 176

Answers (1)

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

Ok, I think I am just invoking iterator wrong. This works ...

SaxonJS.XPath.evaluate( '/foo/text()', xmlDoc,
  {resultForm:'iterator'}).forEachItem( function( node){
    console.log( node)})

Upvotes: 1

Related Questions