开发者

Use E4X with jrunscript?

I use jrunscript for some JavaScript. Works like a charm. Now I wanted to use E4X in JRunScript. The following statements should work:

var x = <hello />;
var y = new XML();

but I get:

js> var x = <hello />;
script error: sun.org.mozilla.javascript.internal开发者_StackOverflow中文版.EvaluatorException:
syntax error (<STDIN>#1) in <STDIN> at line number 1
js> var x = new XML(); 
script error: sun.org.mozilla.javascript.internal.EcmaError:
ReferenceError: "XML" is not defined. (<STDIN>#1) in <STDIN> at line number 1
js> 

Poking around I found references to xmlbeans.jar as prerequisite, but xmlbeans-2.4.0.jar is in lib/ext.

java -version :
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux x86-32
jrunscript -q :
Language ECMAScript 1.6 implemention "Mozilla Rhino" 1.6 release 2

So what do I miss that E4X isnt't available in my jrunscript?


Have a look at Java Scripting Programmer's Guide, specifically:

E4X (ECMAScript for XML - ECMA Standard 357) has been excluded. Use of an XML literal in JavaScript code will result in a syntax error. Note that E4X support is optional in the ECMAScript standard - a implementation can omit E4X support and still be a compliant ECMAScript implementation.


Make sure to set the correct JavaScript version before running your script by either calling version(160) or using the -version 160 launch flag. You would also be able to use 180 (JavaScript 1.8) if you updated Rhino to a much more recent version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜