views:

175

answers:

2

E4X (Ecma-357) is an extension to ECMAScript that adds XML literals as first-class primitives. That's awesome, but with only Mozilla and Adobe support (without V8 and IE support too), E4X is virtually dead from a web developer's perspective that has to support users with any modern browser.

What other work is being done around implementing XML literals in JavaScript? Is there a way to get something similar to XML literals or E4X in JavaScript that anyone is working on? Maybe some plugins for frameworks?

I ran across LunaScript the other day (asana.com/Luna), which has implemented XML literals in their JavaScript-like language. That's great, but I'll probably never work at Asana and therefore never write LunaScript.

+2  A: 

There is an open source project for XML in JavaScript:

http://xmljs.sourceforge.net/

XML for is a powerful, standards-compliant JavaScript XML parser that is designed to help web application designers implement cross platform applications that take advantage of client-side manipulation of XML data. XML for provides a full suite of tools, including:

* A standards-compliant W3C DOM Level 2 processor
* An XPath processor
* A standards-compliant SAX processor
* A simple (classic) DOM processor
* Proxies for XML retrieval from any domain
* Utilities for XML and application development

XML for is Free software and is distrubuted under the terms of the GNU Lesser General Public Licence (LGPL) , an open source license.

Todd Moses
+2  A: 

Personally, I don't think there is any advantage at all to XML literals.

var el= <foo>bar<baz/></foo>;

is not really noticeably better than:

var el= new XML('<foo>bar<baz/></foo>');

There was a reasonable rationale for adding regex literals to JavaScript: that otherwise the backslashes are a super-pain. (Though personally I would have preferred raw strings.) Since backslashes are not common in XML, I don't think there is any such justification there.

Adding the full (complex!) syntax of XML as basic language syntax is not a win. In fact it has caused grievous security problems in practice.

I want E4X gone, not more of the same.

bobince
What about templating? What if you want an object to return all the markup for an JavaScript object? You could declare that markup using XML literals and if that markup is more verbose than just a couple div tags, it would be much easier to write as a literal.
JamesBrownIsDead
Yes, I plan to use E4X for templating of HTML. As a template language, it is quite powerful and elegant. You can embed JS in the XML and further embed XML in that JS.
dlaliberte