简体   繁体   English

SaxonJS.XPath.evaluate 抛出超出最大调用堆栈大小

[英]SaxonJS.XPath.evaluate throws Maximum call stack size exceeded

I am trying to use saxon JS to evaluate some xPaths我正在尝试使用 saxon JS 来评估一些 xPaths

I'm running the following code我正在运行以下代码


const sourceCode= " ... " //a string representing the code source of https://www.imdb.com/chart/boxoffice

const doc = new DOMParser({errorHandler: () => {} }).parseFromString(sourceCode, 'text/html')

try {
        const res = saxon.XPath.evaluate(selectors[0].path, doc,  { xpathDefaultNamespace : 'http://www.w3.org/1999/xhtml' })
        console.log("saxon res", res);
} catch(e) {
        console.log("saxon e", e);
}

which throws the following error抛出以下错误

saxon e RangeError: Maximum call stack size exceeded
at Hb.Cb (/application/node_modules/saxon-js/SaxonJS2N.js:3904:409)
at new Hb (/application/node_modules/saxon-js/SaxonJS2N.js:3905:286)
at Object.fromString (/application/node_modules/saxon-js/SaxonJS2N.js:3948:119)
at H (/application/node_modules/saxon-js/SaxonJS2N.js:4377:39)
at S (/application/node_modules/saxon-js/SaxonJS2N.js:4378:208)
at H (/application/node_modules/saxon-js/SaxonJS2N.js:4378:500)
at /application/node_modules/saxon-js/SaxonJS2N.js:4379:103
at Array.forEach (<anonymous>)
at R (/application/node_modules/saxon-js/SaxonJS2N.js:4379:79)
at Y (/application/node_modules/saxon-js/SaxonJS2N.js:4379:196)
at H (/application/node_modules/saxon-js/SaxonJS2N.js:4379:28)

etc...

Same error for any webpage I have tried.我尝试过的任何网页都出现同样的错误。 How can I parse a source code and evaluate the page with saxon-js我如何解析源代码并使用 saxon-js 评估页面

Note: I'm open to alternatives that use xpath 3.0 Note2: the code above works fine with npm xpath but it uses xpath 1注意:我对使用 xpath 3.0 的替代方案持开放态度 注意 2:上面的代码适用于 npm xpath 但它使用 xpath 1

In the browser Saxon-JS uses the browser's DOM implementation and interoperates fine with eg new DOMParser().parseFromString('...', 'text/html') but I think under Node.js integrates its own DOM based on "third-party components, including sax-js, xmldom, and Big", being "integrated into the saxon-js codebase".在浏览器中,Saxon-JS 使用浏览器的 DOM 实现并与new DOMParser().parseFromString('...', 'text/html')等很好地互操作,但我认为在 Node.js 下集成了自己的基于“第三方组件,包括 sax-js、xmldom 和 Big”,被“集成到 saxon-js 代码库中”。

I don't think they have integrated a text/html parser, so you can parse X(HT)ML using SaxonJS.getResource, but so far not HTML.我认为他们没有集成文本/html 解析器,因此您可以使用 SaxonJS.getResource 解析 X(HT)ML,但到目前为止还没有 HTML。

Example for XML: XML 的示例:

const SaxonJS = require("saxon-js");

const htmlInput = `<html><body><h1>Test</h1>
<p>This is p 1.</p>
<p>This is p2.</p>
</body>
</html>`;

SaxonJS.getResource({ text : htmlInput, type : 'xml' }).then(doc => {

  const result = SaxonJS.XPath.evaluate(`//p/string()`, doc);

  console.log(result);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM