Subj : E4X in Rhino expandos seem buggy To : netscape.public.mozilla.jseng From : Mark Turansky Date : Wed May 25 2005 10:16 am I'm using Java 1.4.2 on W2K and Rhino 1.6. First, the "e4x_examples.js" file runs perfectly well, which lead to my discovering of buggy or at least inconsistent behavior when building XML strings using expandos. In the examples, a new "order" node is created with this statement: order.item[0] = ""; order.item[0].description = "Small Rodents"; The most important thing to note here is the index [0], because in my script below this will not work. This fails with "Error in javascript: TypeError: undefined is not an xml object. (C:\projects\jsx\root\testhtml.jss#8)". Line 14 is 1 var html = ; 2 html.head.title = "My Page Title"; 3 html.body.@bgcolor = "#e4e4e4"; 4 html.body.form.@name = "myform"; 5 html.body.form.@action = "someurl.jss"; 6 html.body.form.@method = "post"; 7 html.body.form.@onclick = "return somejs()"; 8 html.body.form.input[0].@name = "test"; // also fails if line 7 is: html.body.form.input[0] = "" But this works: 8 html.body.form.input.@name = "test"; If I want to add new "input" nodes (and what html form doesn't have many?), this works: 9 html.body.form.input[1] = "" 10 html.body.form.input[1].@name = "testing"; but leaving line 9 out causes an 'undefined' error like above. Why would it be undefined without line 9 when line 8 above doesn't require initialization with an empty string? Why does "input[0]" not work for me, but it works in the examples? I'm glad I am able to figure out its behavior and make it work, but it feels like a hack to add empty strings to elements with [1] but not to [0]. I very much prefer lines like #3, where I just declare the attribute of the node and the node itself is created. On the bright side, using the now-known workarounds that I've discovered, the above script produces perfect xhtml. Mark .