Microsoft Internet Explorer does not follow the W3C DOM Specification and incorrectly ignores whitespace only text nodes. If the Prototype Library Function 'Element.cleanWhitespace( )' is used with Microsoft Internet Explorer. it will remove all nodes, not just whitespace only text nodes as it documents, possibly because of this bug in Microsoft Internet Explorer.
This becomes of extreme annoyance when one wants to walk the DOM using Prototype but also wants to ignore whitespace only text nodes.
To get passed this, I simply do a check for Microsoft Internet Explorer and then decide whether to call 'Element.cleanWhitespace( )' on the element I am going to walk through.
Following is a simple example:
# This example assumes that the element that will be walked through is returned
# from an AJAX Response XML Object.
if( navigator.appName == 'Microsoft Internet Explorer' ) {
Xml = responseObject.responseXML.documentElement;
}
else {
Xml = Element.cleanWhitespace( responseObject.responseXML.documentElement );
}
I really do think that 'Element.cleanWhitespace( )' should be able to detect the
browser automatically and act accordingly.
This code has only been tested in Mozilla Firefox 2.0.x.x and Microsoft Internet Explorer 6.x/7.x.