9

I have a javascript routine that grabs an XML stream via AJAX and then parses it. It works fine in FF and Chrome but in IE 9, if there are consecutive Line Feeds within a node, IE compresses them into a space and one line feed.

Specifically, where retNode is an xml node, retNode.text has the compressed white space in IE, but includes all the characters in FF and Chrome.

I have tried writing my own routine to parse the XML, but that seems fragile and a waste of time. I tried using the PreserveWhitespace property, but that does not seem to be available in javascript. I tried using retNode.nodeValue instead of retNode.text, but nodeValue had no value.

I'd prefer a solution that does not use jquery because I don't know jquery, and I am not sure what other code I would need to add to make jquery work.

Thanks in advance!

4

2 回答 2

1

preserveWhiteSpace在 JavaScript 中可用。

您是否尝试过以下代码?

var xhr = new XMLHttpRequest();
xhr.responseXML.preserveWhiteSpace = true;
…
于 2012-11-16T09:59:01.963 回答
0

它应该只是您丢失的标签之间的空格。非标签之间的空格(例如一对标签中的字符串之间)应始终保留。

换句话说<tag> </tag>,将变为<tag></tag><tag>foo bar</tag>将保持不变。

如果您需要保留两个标签之间的空格,并且preserveWhiteSpace由于某种原因不适合您,那么我认为您必须尽可能放入&#160;您的 XML 源代码(&nbsp;您不能使用的数字版本,因为它是正常情况下的非法 XML 字符,即除非您定义了实体)

于 2012-12-20T21:51:33.687 回答