E4X

jamin on December 6th, 2005

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:

Tags:

2 Responses to “E4X”

  1. 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?

  2. I’ve used the Kubrick theme (with modifications here and there) ever since wordpress 1.5 came out.