Is it possible to detect when IE ignores a whitespace text node from a xml document?

Hixwraryday

New Member
I am trying to write a shim for the text property of the IE XML DOM library, but I have come across an issue regarding formatting whitespace.If I process the text property for the following XML\[code\]var doc1 = load_ie('<root><a>A</a><b>B</b></root>')var doc2 = load_ie('<root><a>A</a> <b>B</b></root>');\[/code\]they give different results:\[code\]doc1.text // 'AB'doc2.text // 'A B' - the multiple spaces are compressed to a single space\[/code\]However, to my surprise, IE doesn't seem to acknowledge the spaces present in x2 even exist, like other browsers do:\[code\]doc1.documentElement.childNodes.length // 2doc2.documentElement.childNodes.length // 2 (I expected 3!)var doc3 = load_ie('<root><a>A</a> c <b>B</b></root>');doc3.documentElement.childNodes.length // 3\[/code\]If I run the tests on Google chrome the number of nodes in the doc2 case is 3 ("a" node, a text node with 3 spaces and the "b" node), similarly to how the doc3 case works. How will I be able to write my shim if IE hides the whitespace node from me and I can't tell apart the first and second cases even though they need to return different results?Code for loading creating XML documents from strings:\[code\]load_ie = function(xmlstr){ var doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async=false; doc.loadXML(xmlstr); return doc;}load_w3c = function(xmlstr){ var p = new DOMParser(); return p.parseFromString(xmlstr, 'text/xml');}\[/code\]Bonus question:I also can't get the example given on the MSDN docs to work either. According to it, the following XML\[code\]var d = load_ie( '<root att=" 123 a ">\n' + ' <a> a a </a>\n' + ' <!-- comment b -->\n' + ' <?pi pi c ?>\n' + ' <![CDATA[ cdata d ]]>\n' + ' e f\n' + '</root>' ); d.text;\[/code\]Should give \[code\]"a a cdata d e f"\[/code\]but instead I get\[code\]"a a cdata d \n e f" \[/code\]I wonder if I am missing something obvious that is causing the weird behavior in my part.
 
Back
Top