我正在尝试运行一个空的简单代码段以在Windows 10的NodeJs v8.11.1上测试SaxonJS 1.1.0。

require('./Saxon-JS-1.1.0/SaxonJS.js');


但是我得到了这个错误:

PS C:\XXX\sandbox\xsl-transformation> node main.js
C:\XXX\xsl-transformation\Saxon-JS-1.1.0\SaxonJS.js:17136
        setPlatform(JSTestDriver.platform);
                    ^
ReferenceError: JSTestDriver is not defined
at initialize (C:\XXX\sandbox\xsl-transformation\Saxon-JS-1.1.0\SaxonJS.js:17136:25)


查看源代码,我可以看到:

function initialize() {
    "use strict";
    if (inBrowser) {
        setPlatform(BrowserPlatform.platform);
        saxonPrint("Saxon-JS " + getProcessorInfo().productVersion + " in browser", 0);
    } else {
        // Currently only Nashorn. (Later need to distinguish from Node case)
        // Nashorn JSTestDriver
        setPlatform(JSTestDriver.platform);
        saxonPrint("Saxon-JS " + getProcessorInfo().productVersion + " in
   Nashorn");

        // node NodePlatform
    }

    if (typeof platform.initialize === "function") {
        platform.initialize();
    }
}


看来Node Platform没有实现。

但是,在documentation中,它写为:


  我们在这里主要是在浏览器中运行Saxon-JS。
  但是,它也可以在服务器端JavaScript中运行
  诸如Node.js的环境(此版本尚未完全支持
  发布)。


我深入搜索了SaxonJS / NodeJS的代码片段,但没有找到。
有人在NodeJS上运行过SaxonJS的代码片段吗?

最佳答案

恐怕文档有点不合时宜。我们确实有一些用户报告说要让代码在Node.js下运行,并且我们自己是在“实验室”中完成的,但是需要对发布的产品进行源代码调整。发布后,代码在两个平台上运行,即浏览器平台和Nashorn(在Nashorn下,它假定我们的测试工具尚未发布)。

我们正在为Node.js开发一个版本。作为产品正确执行此操作需要浏览器版本所没有的许多功能,例如XML解析和序列化,调试支持,命令行界面和API等。

关于node.js - Node.js上的SaxonJS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50984147/

10-12 22:24