admin管理员组

文章数量:1405996

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/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.

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./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.

Share edited Feb 14, 2010 at 5:44 ChrisOh asked Feb 14, 2010 at 5:25 ChrisOhChrisOh 2891 gold badge4 silver badges8 bronze badges 1
  • 2 Side note: E4X is implemented in ActionScript 3. – icktoofay Commented Feb 14, 2010 at 5:27
Add a ment  | 

3 Answers 3

Reset to default 2

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 mon in XML, I don't think there is any such justification there.

Adding the full (plex!) 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.

There is an open source project for XML in JavaScript:

http://xmljs.sourceforge/

XML for <SCRIPT> is a powerful, standards-pliant 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 <SCRIPT> provides a full suite of tools, including:

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

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

js-xml-literal adds support for XML literals in any Javascript engine by means of code rewriting.

https://github./laverdet/js-xml-literal

The syntax is a subset of E4X, however the API mimics the DOM more closely. On the client side, you can interact with the browser's DOM directly using XML literals; and on the server side (NodeJS) you can operate on a virtual DOM before flushing to a string.

本文标签: XML literals in JavaScriptStack Overflow