E4X浏览器支持
我正在尝试解决这个问题,但没有太多信息。哪些浏览器支持 E4X,为什么它没有得到更广泛的采用?
I'm trying to figure this out, but there's not much information. Which browsers support E4X, and why isn't it more widely adopted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Firefox 和其他基于 Mozilla 代码库的浏览器。
因为它几乎没有提供 DOM 等现有标准尚未涵盖的实用功能。
好吧,它比 DOM 使用起来更简单,但是作为代价,您无法访问 XML 的所有功能,而且完全愚蠢的、不必要的 XML 文字/模板语法是 安全灾难,使得即使是完全静态的受 htaccess 保护的文档的作者也不得不担心如何解决该功能。
作为一种访问 XMLHttpRequest 结果的更简单的方法,JSON 完全获胜。对于完整的 XML 处理,您仍然需要 DOM。为了更轻松地处理文档,有选择器、XPath 和 JS 库可以做到这一点,而无需引入奇怪的新语言语法。
这并没有给 E4X 留下太多的利基市场。说实话,我希望它死掉。 (预计到达时间:现在已经基本做到了。)
Firefox and others based on the Mozilla codebase.
Because it offers little practical functionality not already covered by existing standards such as DOM.
OK, it's simpler to use than DOM, but as the price for that you don't get access to all the features of XML, and the thoroughly idiotic, needless XML literal/template syntax is a security disaster, making it so authors of even completely static htaccess-protected documents have to worry about working around the feature.
As a simpler method for accessing the results of an XMLHttpRequest, JSON totally won. For full-on XML processing, you still need DOM. For easier document handling, there are selectors, XPath and JS libraries that can do it without having to introduce weird new language syntax.
That doesn't leave much of a niche for E4X. TBH I wish it would die. (ETA: it has now pretty much done so.)
Firefox 在版本 16 中放弃了 E4X 支持:
Firefox dropped E4X support in version 16:
根据 w3schools 的说法,“Firefox 是目前唯一对 E4X 支持相对较好的浏览器。 ”
您可以尝试使用 XPath 。虽然 XPath 不是跨浏览器的,但有几种 Javascript 解决方案,例如 这个 jQuery 插件。
编辑
你实际上可以使用 jQuery 而不需要插件:
According to w3schools, "Firefox is currently the only browser with relatively good support for E4X."
You could try XPath instead. Although XPath isn't cross-browser there are several Javascript solutions for it like this jQuery plugin.
EDIT
You could actually use jQuery without a plugin for this:
我开发了一个 babel 插件,通过 babel 编译为所有浏览器添加 E4X 基本支持。
https://www.npmjs.com/package/babel-plugin- 您还可以使用 npm simple4x
库将 xml 字符串解析为类似 XML 的对象。
https://www.npmjs.com/package/simple4x
该插件转译以下 E4X:
对于以下 JavaScript:
I have developed a babel plugin that adds E4X basic support to all browsers via babel compilation.
https://www.npmjs.com/package/babel-plugin-transform-simple-e4x
You can also use the npm simple4x library to parse xml strings to a XML like object.
https://www.npmjs.com/package/simple4x
The plugin transpiles the following E4X:
To the following JavaScript: