有没有办法让浏览器忽略或覆盖 xml 样式表处理指令?
我正在尝试编写一个小书签来帮助一些 QA 测试人员在遇到问题时提交有用的调试信息。 目前,我可以将 window.location 设置为提供此调试信息的 URL,但此资源是带有 xml-stylesheet 处理指令的 XML 文档。
如果测试人员能够看到纯文本形式的原始 XML 数据,或者 IE 和 Firefox 的默认 XML 呈现,实际上会更方便。
有谁知道如何使用 Internet Explorer 或 Firefox 禁用或覆盖 XML 文档内提供的 xml-stylesheet 指令?
编辑:我已经针对这个问题开出了赏金。 要求:
- 仅客户端代码,不允许用户干预
- 需要适用于 IE 和 Firefox 的解决方案(它们可以是不同的解决方案)
- 禁用样式表处理并将其呈现为文本是可以接受的
- 使用自定义 XSL 覆盖样式表处理是可以接受的
- 使用浏览器默认 XML 样式表是可接受的
I'm trying to write a bookmarklet to help some QA testers submit useful debugging information when they come across issues. Currently I can set window.location to a URL that provides this debugging information, but this resource is an XML document with an xml-stylesheet processing directive.
It would actually be more convenient if the testers were able to see either the raw XML data as plain text, or the default XML rendering for IE and Firefox.
Does anyone know a way to disable or override xml-stylesheet directives provided inside an XML document, using Internet Explorer or Firefox?
Edit: I've opened a bounty on this question. Requirements:
- Client-side code only, no user intervention allowed
- Solutions for both IE and Firefox needed (they can be different solutions)
- Disabling stylesheet processing and rendering it as text is acceptable
- Overriding stylesheet processing with a custom XSL is acceptable
- Rendering the XML with the browser default XML stylesheet is acceptable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
据我所知,没有办法做你想做的事。 问题是,javascript 无法从客户端 xml/xsl 转换读取 xml 的 dom。 就 javascript 而言,它是在普通的 html dom 上执行的。
然而,根据网络应用程序的类型,可能会有一些希望。 您可以使用 ajax 来获取当前 url 的 xml。 只要没有发布数据或任何其他随机性,此方法就应该可以正常工作。
As far as I know, there is no way of doing what you are trying to do. The issue is, javascript cannot read the dom of the xml from a client side xml/xsl transform. As far as the javascript is concerned, it is executing on a normal html dom.
However, there may be some hope depending on the type of webapp. You could use ajax to get the xml of the current url. As long as there is no post data, or any other randomness, this method should work fine.
编辑:太糟糕了,虽然预览中一切看起来都很好,但可点击的示例似乎把事情搞乱了......也许布局在历史上是好的。
我听说 IE 和 Firefox 都支持“view-source:”伪协议,但无法验证 IE。 Mac 上的 Firefox 确实可以理解,但 Safari 不能。
以下小书签不会触发 XML。 尽管 Firefox 会使用某些颜色进行渲染,但它不会执行通常用于 的默认转换没有任何 XSLT 的 XML(因此,查看源代码的结果不会产生 Firefox 通常显示的可折叠文档树):
当使用 Ajax 获取文档时,不限于
alert
EDIT: too bad, though all seemed fine in the preview, the clickable examples seem to mess up things... Maybe the layout is fine in the history.
I've heard, but cannot validate for IE, that both IE and Firefox support the "view-source:" pseudo-protocol. Firefox on Mac indeed understands it, but Safari does not.
The following bookmarklet will not trigger the XSLT transformation specified in the XML. And though Firefox will render this using some colours, it does not execute the default transformation it would normally use for XML without any XSLT (so, the result of view-source does NOT yield a collapsable document tree that Firefox would normally show):
When fetching the document using Ajax then one is not limited to the
alert
oneporter used, but can display it in a new window as well. Again: this will not invoke the XSLT transformation that is specified:你不能在两个浏览器中都执行“查看源代码”吗?
Can't you just do "View Source" in both browsers?
您可以在内容输出到浏览器之前使用中间步骤来预处理 XML,从而避免处理指令。
客户端建议
服务器端建议
不要直接请求相关的 XML 文档,而是向代理脚本发出请求,该代理脚本从 XML 内容中删除所有处理指令,或者实际上一切你不想要的。
而不是:
使用:
http://example.com/proxy/ 处的脚本将:
document.xml
You can avoid a processing instruction by using an intermediary step to pre-process the XML before the content is output in the browser.
Client-side suggestion
Server-side suggestion
Instead of directly requesting the pertinent XML document, make a request instead to a proxy script that removed from the XML content all processing instructions, or indeed all that you don't want.
Instead of:
use:
The script at http://example.com/proxy/ would:
document.xml
只要您不需要处理跨域权限,带有 XML 源的简单 ajax 请求/警报框就可以解决问题。 您必须在 xmlHttp 声明中添加一些内容,以使其与 IE 兼容。
As long as you wouldn't have to deal with cross domain permissions, a simple ajax request / alert box with the XML source would do the trick. You'll have to add a little bit to the xmlHttp declaration to make it compatible with IE.