E4X is a JavaScript extension that adds native XML support and Firefox 1.5 has partial support. Here’s a silly example. If you’re running Firefox 1.5 you should see the list below of me and my siblings:
The code looks like this:
<script type="application/x-javascript; version=1.5; e4x=1">
var siblings =
<people>
<person>
<name>Jamin</name>
<url>http://pubcrawler.org</url>
</person>
<person>
<name>Lauren</name>
<url>http://laurengray.blogspot.com</url>
</person>
<person>
<name>Noah</name>
<url>http://www.missouri.edu</url>
</person>
<person>
<name>Micah</name>
<url>http://micahgray.com</url>
</person>
</people>;
function makeList(siblings) {
var list = <ul/>;
list.@style = "list-style: square";
var people = siblings..person;
for each (var person in people) {
var name = person.name.text();
var url = person.url.text();
list.li += <li><a href={url}>{name}</a></li>;
}
return list;
}
var list = makeList(siblings);
document.write(list);
</script>
Notice I can inline the XML and manipulate attributes easily.
Related Links:
- Weiqi Gao has a neat example which retrieves an RSS feed using XMLHttpRequest() and displays it in a table
- AJAX and scripting Web services with E4X, Part 1
- AJAX and scripting Web services with E4X, Part 2
- Mozilla e4x Presentation at XTech 2005
Tags: Web
December 7th, 2005 at 6:40 am
You know what was really kind of cool? The post originally came to my RSS reader, Vienna. The list was all in asian font.
But it looks right on Firefox 1.5 for OS X…
When did you change to Kubrick?
December 7th, 2005 at 11:31 am
I’ve used the Kubrick theme (with modifications here and there) ever since wordpress 1.5 came out.