Ticket #12151 (closed bug: invalid)
IE 10 jQuery.parseXML
| Reported by: | mattBate | Owned by: | mattBate |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.8b2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When trying to parse xml in IE 10 jQuery uses the window.DOMParser method rather than the activeXObject method used in previous versions of IE.
This apears to work, however the object returned is not the same type and doesn't have the same set of methods as the domParser returns in Chrome and FF.
I think the logic needs to be reversed to test for the presence of ActiveX rather than testing for the presence of window.DOMParser.
Hope this makes sense.
Matt
Change History
comment:1 Changed 10 months ago by dmethvin
- Owner set to mattBate
- Status changed from new to pending
comment:2 Changed 10 months ago by mattBate
- Status changed from pending to new
I would provide a jsFiddle for this but our network at work is so restricted that site doesn't work.
I'm trying to do something similar to this, where the XML has been scraped from the screen and is passed in to parse XML as a string.
The system i'm working on has various parts where the IE/other browsers split. but in IE 10 the returned Object from the XML has neither an evaluate or selectSingleNode method, it's a different object type again. A new third way!
Code:
var testingXML = jQuery.parseXML('<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading></note>')
if (testingXML.evaluate) {
// Non-IE
var xmlnodes = testingXML.evaluate("//to", testingXML, null, XPathResult.ANY_TYPE, null);
if (xmlnodes != null) {
var node = xmlnodes.iterateNext();
strRet = node.textContent;
}
}
else {
// Internet Explorer
var node = testingXML.selectSingleNode("//to");
if (node != null)
strRet = node.text;
}
console.log(strRet)
comment:3 Changed 10 months ago by dmethvin
- Status changed from new to pending
What I'm looking for is some indication that IE10 is doing something that contradicts a standard. This is DOMParser: http://html5.org/specs/dom-parsing.html
It returns a Document, in particular an XMLDocument for this case. http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#xmldocument
No .evaluate() or .selectSingleNode() there. And indeed the example doesn't work on IE9:
Are you just looking for a portable way to get the info?
Again, some links to controlling standards or an example of how it could be made better (or was recently made worse) would be helpful.
comment:4 Changed 10 months ago by neil.big.craig@…
I have run into this issue as well. Having missed the fact that the returned object has no .evaluate method, I tried extending the object prototype like so:
if (document.implementation.hasFeature("XPath", "3.0"))
{
if (typeof XMLDocument == "undefined") { XMLDocument = Document; }
XMLDocument.prototype.selectNodes = function (cXPathString, xNode)
{
if (!xNode) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for (var i = 0; i < aItems.snapshotLength; i++) { aResult[i] = aItems.snapshotItem(i); }
return aResult;
}
XMLDocument.prototype.selectSingleNode = function (cXPathString, xNode)
{
if (!xNode) { xNode = this; }
var xItems = this.selectNodes(cXPathString, xNode);
if (xItems.length > 0) { return xItems[0]; }
else { return null; }
}
Element.prototype.selectNodes = function (cXPathString)
{
if (this.ownerDocument.selectNodes) { return this.ownerDocument.selectNodes(cXPathString, this); }
else { throw "For XML Elements Only"; }
}
Element.prototype.selectSingleNode = function (cXPathString)
{
if (this.ownerDocument.selectSingleNode) { return this.ownerDocument.selectSingleNode(cXPathString, this); }
else { throw "For XML Elements Only"; }
}
}
But it seems like the document implementation, does not have any XPath feature. But since it has no .evaluate, I instead override the parseXML of jQuery with one that will implement the ActiveX MSXML instead of using the DOMParser.
comment:5 Changed 10 months ago by SeanH
I added comments to this ticket which I believe is related #4958.
comment:6 Changed 9 months ago by GotDibbs
I believe IE9 and IE10 are both missing XPath support on Documents meaning that 'selectSingleNode', 'evaluate' and 'selectNodes' are all missing. The recommended approach given here: http://stackoverflow.com/questions/3820757/ie9-selectsinglenode-missing-from-beta-how-to-overcome-this-in-javascript is to switch to querySelector or just fallback to the ActiveX object. I have personally fallen back on the ActiveX object as I've found the alternative to be too drastically different in order to implement with old browsers in mind.
comment:7 Changed 9 months ago by trac-o-bot
- Status changed from pending to closed
- Resolution set to invalid
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Some related information regarding the effect on XHR: http://blogs.msdn.com/b/ie/archive/2012/07/19/xmlhttprequest-responsexml-in-ie10-release-preview.aspx
Matt, can you provide some more detail about what is different, including a reference to pages?