David Flanagan's excellent book on JavaScript has an example that shows how to perform XPath queries in IE. On page 518 of fifth edition, you can see the following code snippet taken from example 21-10:
// In IE, the context must be an Element not a document,
// so if the context is a document, use the documentElement instead
if (context == doc) context = doc.documentElement;
return context.selectNodes(this.xpathText);
I found out the hard way that this code is absolutely necessary. It appears (although I cant understand why) that on IE XMLHttpRequest seems to to randomly return a reference to either the document corresponding to the received XML or the documentElement. Whats happening here?
I believe you answered your own question, every so often IE returns a reference to the document, or to the document element, the if statement is simply a quick conditional to fix it if needed.
If you are asking why IE does it, I don't think anyone here is going to be able to give that answer....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With