【问题标题】:Iteration through a Saxon-JS sequence遍历 Saxon-JS 序列
【发布时间】:2018-08-20 01:33:55
【问题描述】:

此 javascript(托管在浏览器控制台上)...

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

...返回错误...

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

...而不是预期的输出...

"Stuff"

为什么?

根据documentation here,evaluate() 表达式应该返回一个迭代器。但事实并非如此。

使用的库包括:

  1. jQuery;和
  2. Saxon-jsjavascript 库。

更新

我可以使用这个替代表达式获得功能正确的结果...

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

...但如果可能的话,我真的想使用惰性迭代器,而不是数组。

【问题讨论】:

    标签: javascript saxon-js


    【解决方案1】:

    好的,我想我只是错误地调用了迭代器。这行得通...

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

    【讨论】:

      猜你喜欢
      • 2015-03-17
      • 2014-01-17
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 2020-09-08
      相关资源
      最近更新 更多