IE xml 解析器取出空格
我注意到 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 技术交流群。

发布评论
评论(2)
根据 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);
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如果元素没有设置
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.