Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Baffled by an XPath issue on IE

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?

like image 914
Rangachari Anand Avatar asked Nov 14 '22 16:11

Rangachari Anand


1 Answers

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....

like image 88
Mitchel Sellers Avatar answered Dec 19 '22 19:12

Mitchel Sellers