JavaScript 中的 XML 文字?

发布于 2024-08-21 00:09:24 字数 368 浏览 5 评论 0原文

E4X (Ecma-357) 是 ECMAScript 的扩展,它将 XML 文字添加为第一类原语。这太棒了,但只有 Mozilla 和 Adob​​e 支持(也不支持 V8 和 IE),从必须支持使用任何现代浏览器的用户的 Web 开发人员的角度来看,E4X 实际上已经死了。

围绕在 JavaScript 中实现 XML 文字还做了哪些其他工作?有没有办法在 JavaScript 中获得类似于 XML 文字或 E4X 的东西,任何人都在研究?也许有一些框架插件?

前几天我遇到了 LunaScript (asana.com/Luna),它用类似 JavaScript 的语言实现了 XML 文字。那太好了,但我可能永远不会在 Asana 工作,因此永远不会编写 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.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梅倚清风 2024-08-28 00:09:24

就我个人而言,我不认为 XML 文字有任何优势。

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

并没有明显好于:

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

向 JavaScript 添加正则表达式文字有一个合理的理由:否则反斜杠将是一个超级痛苦。 (尽管我个人更喜欢原始字符串。)由于反斜杠在 XML 中并不常见,所以我认为没有任何这样的理由。

添加 XML 的完整(复杂!)语法作为基本语言语法并不是一个胜利。事实上,它在实践中造成了严重的安全问题

我希望 E4X 消失,而不是变得更加一样。

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.

萝莉病 2024-08-28 00:09:24

有一个 JavaScript 中的 XML 开源项目:

http://xmljs.sourceforge.net/

XML for

* 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

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.

嘦怹 2024-08-28 00:09:24

js-xml-literal 通过代码重写的方式在任何 Javascript 引擎中添加对 XML 文字的支持。

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

语法是E4X 的子集,但 API 更接近地模仿 DOM。在客户端,您可以直接使用 XML 文字与浏览器的 DOM 进行交互;在服务器端(NodeJS),您可以在刷新到字符串之前对虚拟 DOM 进行操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文