Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 9 compresses white space within XML DOM

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!

like image 904
user1647747 Avatar asked Sep 05 '12 02:09

user1647747


1 Answers

preserveWhiteSpace is available in JavaScript.

Have you tried the following code?

var xhr = new XMLHttpRequest();
xhr.responseXML.preserveWhiteSpace = true;
…
like image 134
Julien Royer Avatar answered Nov 19 '22 17:11

Julien Royer