mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-05 12:25:47 +01:00
0a0bd4560177dd8a89c3978dee0c61dd8dd0a932
Delivered-To: maglione.k@gmail.com Received: by 10.216.136.214 with SMTP id w64cs2667wei; Fri, 10 Sep 2010 00:53:12 -0700 (PDT) Return-Path: <dougkearns@gmail.com> Received-SPF: pass (google.com: domain of dougkearns@gmail.com designates 10.227.138.146 as permitted sender) client-ip=10.227.138.146; Authentication-Results: mr.google.com; spf=pass (google.com: domain of dougkearns@gmail.com designates 10.227.138.146 as permitted sender) smtp.mail=dougkearns@gmail.com; dkim=pass header.i=dougkearns@gmail.com Received: from mr.google.com ([10.227.138.146]) by 10.227.138.146 with SMTP id a18mr590354wbu.151.1284105192263 (num_hops = 1); Fri, 10 Sep 2010 00:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=8pQUW5WLnsK61m2IZPWOnOPaQlu/k2jhkbbOFOecr2A=; b=W/+613sGtVKvI12FR9kJjsK4c4c2tUpTk9WgTdUFhFXItgDA8yaTCnb2zrzYbn+ReP yXyrVWu+fFAeNQKtk3afP+gKh9HlCNufq6UIoLRk9k2jwCsIoUO75FXbSk7MXL4Q1G2y NYDYeWNUccCowS2PRPiHgM0Vt+Af0nU/tM6T4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=w4FhoErEFuUuIoaJOAnwhJjs1flQd2Yz5nkbRlPcLLhMm0qhUMg62PJ7uMCsJv9mdr +nGqpFplrRmAhsU2KTAf1k8vqJ+SWYNnSpE+axoyUFCZ+Xc9OfvWvsVF8cVg46wmkUKF y6uJJYEoMmpAfYQeX7rchyTlGhU9g7Mm2YZUk= Received: by 10.227.138.146 with SMTP id a18mr590354wbu.151.1284105192249; Fri, 10 Sep 2010 00:53:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.135.131 with HTTP; Fri, 10 Sep 2010 00:52:52 -0700 (PDT) Message-ID: <AANLkTi=F6XwDTh+++ph4Qdw5pm3YAMvwvZNBi49nU84=@mail.gmail.com> To: Kris Maglione <maglione.k@gmail.com> Content-Type: multipart/mixed; boundary=00163645735ad6998c048fe309e3
A terse introduction to E4X
Public Domain
The inline XML literals in this code are part of E4X, a standard
XML processing interface for ECMAScript. In addition to syntax
for XML literals, E4X provides a new kind of native object,
"xml", and a syntax, similar to XPath, for accessing and
modifying the tree. Here is a brief synopsis of the kind of
usage you'll see herein:
> let xml =
<foo bar="baz" baz="qux">
<bar>
<baz id="1"/>
</bar>
<baz id="2"/>
</foo>;
// Select all bar elements of the root foo element
> xml.bar
<bar><baz id="1"/></bar>
// Select all baz elements anywhere beneath the root
> xml..baz
<baz id="1"/>
<baz id="2"/>
// Select all of the immediate children of the root
> xml.*
<bar><baz id="1"/></bar>
<baz id="2"/>
// Select the bar attribute of the root node
> xml.@bar
baz
// Select all id attributes in the tree
> xml..@id
1
2
// Select all attributes of the root node
> xml.@*
baz
quz
// Add a quux elemend beneath the first baz
> xml..baz[0] += <quux/>
<baz id="1"/>
<quux/>
> xml
<foo bar="baz" baz="qux">
<bar>
<baz id="1"/>
<quux/>
</bar>
<baz id="2"/>
</foo>
// and beneath the second
> xml.baz[1] = <quux id="1"/>
> xml
<foo bar="baz" baz="qux">
<bar>
<baz id="1"/>
<quux/>
</bar>
<baz id="2"/>
<quux id="1"/>
</foo>
// Replace bar's subtree with a foo element
> xml.bar.* = <foo id="1"/>
> xml
<foo bar="baz" baz="qux">
<bar>
<foo id="1"/>
</bar>
<baz id="2"/>
<quux id="1"/>
</foo>
// Add a bar below bar
> xml.bar.* += <bar id="1"/>
<foo id="1"/>
<bar id="1"/>
> xml
<foo bar="baz" baz="qux">
<bar>
<foo id="1"/>
<bar id="1"/>
</bar>
<baz id="2"/>
<quux id="1"/>
</foo>
// Adding a quux attribute to the root
> xml.@quux = "foo"
foo
> xml
<foo bar="baz" baz="qux" quux="foo">
<bar>
<foo id="1"/>
<bar id="1"/>
</bar>
<baz id="2"/>
<quux id="1"/>
</foo>
> xml.bar.@id = "0"
> xml..foo[0] = "Foo"
Foo
> xml..bar[1] = "Bar"
Bar
> xml
js> xml
<foo bar="baz" baz="qux" quux="foo" id="0">
<bar id="0">
<foo id="1">Foo</foo>
<bar id="1">Bar</bar>
</bar>
<baz id="2"/>
<quux id="1"/>
</foo>
// Selecting all bar elements where id="1"
> xml..bar.(@id == 1)
Bar
// Literals:
// XMLList literal. No root node.
> <>Foo<br/>Baz</>
Foo
<br/>
Baz
// Interpolation.
> let x = "<foo/>"
> <foo bar={x}>{x + "<?>"}</foo>
<foo/><?>
> <foo bar={x}>{x + "<?>"}</foo>.toXMLString()
<foo bar="<foo/>"><foo/><?></foo>
> let x = <foo/>
> <foo bar={x}>{x}</foo>.toXMLString()
<foo bar="">
<foo/>
</foo>
Description
Languages
JavaScript
93.7%
C++
1.8%
CSS
1.6%
XSLT
1.3%
Vim script
0.8%
Other
0.6%