JavaScript XML literals?

E4X (Ecma-357) is an ECMAScript extension that adds XML literals as first-class primitives. This is amazing, but only with support for Mozilla and Adobe (without support for V8 and IE), E4X practically does not work from the point of view of web developers, which should support users with any modern browser.

What else is being done to inject XML literals into 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 came across LunaScript the other day (asana.com/Luna), which implemented XML literals in its JavaScript-like language. This is great, but I will probably never work in Asana and therefore I will never write LunaScript.

+6
javascript xml e4x primitive
source share
3 answers

JavaScript has an open source project for XML:

http://xmljs.sourceforge.net/

XML for <SCRIPT> is a powerful standards-compliant XML parser designed to help web application developers implement cross-platform applications that take advantage of client-side XML data processing. XML for <SCRIPT> provides a complete set 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 distributed under the terms of the GNU Lesser General Public License (LGPL), an open source license.

+2
source share

Personally, I don't think there are any benefits to XML literals.

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

actually not noticeably better than:

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

There was a reasonable rationale for adding regular expression literals to JavaScript: otherwise, the backslash is a super pain. (Although I personally would prefer raw strings.) Since backslashes are not common in XML, I don’t think there is such an excuse.

Adding the full (complex!) XML syntax as the base language syntax is not a win. In fact, this actually caused severe security problems .

I want the E4X to leave, nothing more.

+2
source share

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

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

Syntax is a subset of E4X, but the API mimics the DOM more. On the client side, you can directly interact with the browser DOM using XML literals; and on the server side (NodeJS) you can work with the virtual DOM before loading it into a string.

+1
source share

All Articles