XML literals in JavaScript?
Asked Answered
T

3

6

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.

Tapes answered 14/2, 2010 at 5:25 Comment(1)
Side note: E4X is implemented in ActionScript 3.Hippomenes
P
2

There is an open source project for XML in JavaScript:

http://xmljs.sourceforge.net/

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

Palpitation answered 14/2, 2010 at 5:41 Comment(0)
B
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 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.

Bobettebobina answered 14/2, 2010 at 10:13 Comment(3)
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.Helicograph
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.Apophyge
That link doesn't work anymore. I get "Your client does not have permission to get URL /p/doctype/wiki/ArticleE4XSecurity from this server."Lolland
B
1

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

https://github.com/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.

Benison answered 6/1, 2011 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.