IE xml 解析器取出空格

发布于 12-25 06:12 字数 155 浏览 2 评论 0原文

我注意到 ie xml 解析器的行为与其他浏览器不同。例如,xml 文档中的空格本身不能作为文本节点,因此会被删除。不幸的是,我可能在 xml 文件中生成了空数据。我放入的这些空格可以防止数据在其他浏览器中变为空。有没有办法在使用 ie 浏览器时保留这些空格?我不想修改 xml 文件本身。谢谢!

I've noticed that ie xml parser behaves differently from other browsers. For instance spaces in the xml document cannot stand as textnodes by themselves and are removed. Unfortunately I may have null data that is generated in the xml file. Those spaces that I've put in keeps the data from becoming null in other browsers. Is there a way to preserve these spaces in ie when using their browser? I do not want to modify the xml file itself. Thanks!

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

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

发布评论

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

评论(2

一身骄傲2025-01-01 06:12:48

如果元素没有设置 xml:space="preserve" 属性,IE 的行为是正确的。您可以简单地在文档中设置此属性(在空间很重要的最顶层元素上)。

有关详细信息,请参阅XML 标准第 2.10 节

IE's behavior is correct if the elements do not have the attribute xml:space="preserve" set. You can simply set this attribute (on the topmost element(s) where space matters) in your document.

For more information, refer to section 2.10 of the XML standard.

秋叶绚丽2025-01-01 06:12:48

根据 MSDN http://msdn.microsoft.com/en-us/library/ms256097 .aspx

默认情况下,Microsoft XML 核心服务 (MSXML) 不支持 xml:space 属性。如果应用程序必须遵守 xml:space 属性,则在解析之前必须将 DOMDocument 对象的preserveWhiteSpace 属性设置为True。

xmldoc= new ActiveXObject("Msxml2.DOMDocument.5.0");
xmldoc.preserveWhiteSpace = true;
xmldoc.load(url);

according MSDN http://msdn.microsoft.com/en-us/library/ms256097.aspx

By default, Microsoft XML Core Services (MSXML) does not honor the xml:space attribute. If an application must honor the xml:space attribute, the preserveWhiteSpace property of the DOMDocument object must be set to True prior to parsing.

xmldoc= new ActiveXObject("Msxml2.DOMDocument.5.0");
xmldoc.preserveWhiteSpace = true;
xmldoc.load(url);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文