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?