1 A terse introduction to E4X
4 The inline XML literals in this code are part of E4X, a standard
5 XML processing interface for ECMAScript. In addition to syntax
6 for XML literals, E4X provides a new kind of native object,
7 "xml", and a syntax, similar to XPath, for accessing and
8 modifying the tree. Here is a brief synopsis of the kind of
9 usage you'll see herein:
12 <foo bar="baz" baz="qux">
19 // Select all bar elements of the root foo element
21 <bar><baz id="1"/></bar>
23 // Select all baz elements anywhere beneath the root
28 // Select all of the immediate children of the root
30 <bar><baz id="1"/></bar>
33 // Select the bar attribute of the root node
37 // Select all id attributes in the tree
42 // Select all attributes of the root node
47 // Add a quux elemend beneath the first baz
48 > xml..baz[0] += <quux/>
52 <foo bar="baz" baz="qux">
60 // and beneath the second
61 > xml.baz[1] = <quux id="1"/>
63 <foo bar="baz" baz="qux">
72 // Replace bar's subtree with a foo element
73 > xml.bar.* = <foo id="1"/>
75 <foo bar="baz" baz="qux">
83 // Add a bar below bar
84 > xml.bar.* += <bar id="1"/>
88 <foo bar="baz" baz="qux">
97 // Adding a quux attribute to the root
101 <foo bar="baz" baz="qux" quux="foo">
111 > xml..foo[0] = "Foo"
113 > xml..bar[1] = "Bar"
117 <foo bar="baz" baz="qux" quux="foo" id="0">
119 <foo id="1">Foo</foo>
120 <bar id="1">Bar</bar>
126 // Selecting all bar elements where id="1"
127 > xml..bar.(@id == 1)
131 // XMLList literal. No root node.
139 > <foo bar={x}>{x + "<?>"}</foo>
141 > <foo bar={x}>{x + "<?>"}</foo>.toXMLString()
142 <foo bar="<foo/>"><foo/><?></foo>
145 > <foo bar={x}>{x}</foo>.toXMLString()