【问题标题】:Rhino 1.7r2-3 E4X "XML" is not definedRhino 1.7r2-3 E4X“XML”未定义
【发布时间】:2011-11-18 13:15:53
【问题描述】:

我无法使用 JDK 6 运行以下代码。 它抛出一个异常:

线程“main”org.mozilla.javascript.EcmaError 中的异常:ReferenceError:“XML”未定义。

我的环境如下:Ubuntu 11.04、JDK 6、Rhino 1.7R2(也用 Rhino 1.7R3 测试过)

    String script = "function abc(x) {var dd = new XML();}";
    Context context = Context.enter();
    try {
        ScriptableObject scope = context.initStandardObjects();
        Scriptable that = context.newObject(scope);

        Function fct = context.compileFunction(scope, script, "script", 1, null);
        Object result = fct.call(context, scope, that, new Object[] {2});

    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally {
        Context.exit();
    }

【问题讨论】:

  • 您能否验证您使用的是正确的 Mozilla Rhino js.jar 文件。我使用 Eclipse 和 Rhino 1.7R2 和 1.7R3 在 Windows 和 Ubuntu Linux 11.04 上尝试了您的示例,并且一切执行都没有任何错误。

标签: java javascript xml rhino e4x


【解决方案1】:

我遇到了同样的问题 → 在 Rhino shell E4X 中完美运行,但在嵌入模式下 – ReferenceError: "XML" is not defined.

旧的 Xerces 有问题,运行我的应用程序时,我的类路径中有 2.6.2。当我将它更新到 2.11 时,问题就消失了。

$ java -cp js.jar:xerces-2.6.2.jar org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 3 2011 05 09
js> var x = <foo/>;
js: uncaught JavaScript runtime exception: ReferenceError: "XML" is not defined.

$ java -cp js.jar org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 3 2011 05 09
js> var x = <foo/>;
js> x.toXMLString();
<foo/>

看起来当 Rhino 找到 Xerces 时,它使用它,而不是自己的机制来解析 XML(当我仅在类路径中使用 js.jar 启动 Shell 时)。

【讨论】:

  • 我知道 )) 我已经解决了这个问题。不过还是谢谢你的回复 ))
猜你喜欢
  • 1970-01-01
  • 2016-05-28
  • 2012-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
  • 2011-12-26
相关资源
最近更新 更多