pjr, thank you very much for the solution. More importantly thanks for the E4X resource. I was googling with wrong keywords. I was able to get the E4X spec document, now. Thanks again.
nk4um
Javascript E4X tutorial and examples
| Poster | Content | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
nk4um User
Posts: 2
|
||||||||||||||||||
|
nk4um Moderator
Posts: 755
|
I was playing around and that got left in the example!
|
|||||||||||||||||
|
nk4um Moderator
Posts: 755
|
The answer seems to be in section ''11.2.1 Property Accessors'' of the E4X spec. This works...
Maybe there''s an elegant escaping syntax but I haven''t found it yet! Cheers Pete |
|||||||||||||||||
|
nk4um User
Posts: 2
|
I have an xml document as follows
<doc> <node> <node.1> hello </node.1> <node.1> world </node.1> <node.1> welcome to </node.1> <node.1> E4X </node.1> </node> </doc> How do I iterate over node.1? I would like to something like for each ( text in doc..node.1 ) { print (text); } Right now, I can''t do this because of period in the node name. Rhino interpreter is throwing an error. ''missing ) after for-loop control'' Can someone help me? Thanks. |
|||||||||||||||||
|
nk4um Moderator
Posts: 485
|
First things first, are you using NetKernel version 2.0.6 as E4X support is new feature? Secondly try running the E4X example
in the Developer Tools -> Script Playpen - does that work?
If you get this far then it is likely a configuration issue within your development module. What is you setup? (OS/JVM version/ How are you using E4X - in a custom module/ in workbench) Cheers, Tony |
|||||||||||||||||
|
nk4um User
Posts: 1
|
The information you gave was very valuable. But i think i need more help. I have set up problems. Can you go over what is
need to start with rhino. I cant write js including XML data type. The error is "XML" is not defined. What could be the problem...
|
|||||||||||||||||
|
nk4um Moderator
Posts: 485
|
I''ve been playing with E4X within the NetKernel scripting framework because I wanted to see if the tight language binding
between Javascript and XML really made writing scripts to process XML easier and more compact.
The conclusion: E4X really works well despite a few rough edges. Getting into E4X, though, was hard because there are not many good sources of example code out there to use. The specification is not that helpful to actually work out how to use it: http://www.ecma-international.org/publications/standards/Ecma-357.htm One page this page of E4X tests which was very helpful: http://bclary.com/2004/10/03/js-tests/menubody.html Here is quick cookbook of some code snippets I''ve discovered: Cookbook create a literal document:
create cursor into document
add/assign an attribute
delete a node:
iterate over nodes:
find all decendants:
insert a new fragment:
insert a new fragment at beginning:
parameterized locate:
parameterized text in literal:
parameterized attribute in literal:
count matches:
NetKernel specific Source an external resource as an XML object:
Create a response from an XML object:
Process an XML object with an XSLT transform:
Strange things I''ve noticed Building an XML object from an XmlObject when there is a leading comment, for example with this doc:
You end up with a doc just containing a comment and no root element if you:
Building an XML object from a String when there are an comments - all comments get lost! |