JavaScript 中的 XML 文字?
E4X (Ecma-357) 是 ECMAScript 的扩展,它将 XML 文字添加为第一类原语。这太棒了,但只有 Mozilla 和 Adobe 支持(也不支持 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就我个人而言,我不认为 XML 文字有任何优势。
并没有明显好于:
向 JavaScript 添加正则表达式文字有一个合理的理由:否则反斜杠将是一个超级痛苦。 (尽管我个人更喜欢原始字符串。)由于反斜杠在 XML 中并不常见,所以我认为没有任何这样的理由。
添加 XML 的完整(复杂!)语法作为基本语言语法并不是一个胜利。事实上,它在实践中造成了严重的安全问题。
我希望 E4X 消失,而不是变得更加一样。
Personally, I don't think there is any advantage at all to XML literals.
is not really noticeably better than:
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.
有一个 JavaScript 中的 XML 开源项目:
http://xmljs.sourceforge.net/
XML for
是一个功能强大、符合标准的 JavaScript XML 解析器,旨在帮助 Web 应用程序设计人员实现利用 XML 数据的客户端操作的跨平台应用程序。XML for
提供了一整套工具,包括:XML for
是自由软件,根据 GNU Lesser General Public 条款分发许可证(LGPL),一种开源许可证。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: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 通过代码重写的方式在任何 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.