XMLHttpRequest responseXML in IE10 Release Preview


IE10 in Windows 8 Release Preview updates
the responseXML from an XMLHttpRequest to return a native
XML document by default. This change applies to IE10’s Standards and Quirks
document modes, making them interoperable with other modern browsers and consistent
with a “same markup” approach. Compatibility document modes 5, 7, 8, and 9 are unchanged.

This change may impact sites that were expecting responseXML to contain
an MSXML document and depended on MSXML-specific functionality such as selectNodes. In these cases, you may request that IE10 return an MSXML by setting
the responseType member of your XMLHttpRequest object to 'msxml-document'. If your code does not depend on MSXML-specific functionality, IE10’s native XML document should work for you.

Native XML support in IE9 brought DOM parity to XML and HTML and enabled XML fragments
to be inserted and rendered directly within a page (even in HTML). IE9 also simplified
converting between XML and DOM with the addition of
DOMParser and XMLSerializer
. IE10 completes this transition by updating
responseXML to return a native XML document.

Like IE9, IE10 previews before the Windows 8 Release
Preview
returned an
MSXML
document for responseXML. As a result, retrieving
a native document required the additional step of passing responseText
to DOMParser.

var xhr = new
XMLHttpRequest();

//...

var parser = new
DOMParser();

var doc = parser.parseFromString(xhr.responseText,
'text/xml');

// 'doc' contains a native document
in both IE9 and IE10

In the Windows 8 Release Preview, IE10 eliminates the need for an additional DOMParser
step by returning a native document directly via responseXML. Existing
code using DOMParser will continue to work in IE10.

var xhr = new
XMLHttpRequest();

//...

var doc = xhr.responseXML;

// 'doc' contains a native document
in IE10’s Standards and Quirks document modes

// it contains an MSHTML document
in IE9 and in IE10’s compatibility document modes

This simplification also applies to the new response property when
responseType is set to 'document'.

var xhr = new
XMLHttpRequest();

xhr.open(method, url, true);

xhr.responseType = 'document';

//...

var doc = xhr.response;

// 'doc' contains a native document
in IE10’s Standards and Quirks document modes

IE10 additionally includes a mechanism to opt-in to retrieving an MSXML document.
This can be useful if you still need some MSXML-specific functionality (such as
selectNodes
) or simply need some extra time to migrate. To do this, set
the responseType of your XMLHttpRequest object to 'msxml-document'.

var xhr = new
XMLHttpRequest();

xhr.open(method, url, true);

try { xhr.responseType =
'msxml-document'
; } catch(e){}

//...

var doc = xhr.responseXML;

// 'doc' now contains an MSXML document
in IE10’s Standards and Quirks document modes

In theory the assignment should be ignored by other browsers, but in practice some
do throw an exception. You can defend against this using a try/catch
statement, as in the above example.

—Tony Ross, Program Manager, Internet Explorer

Comments (24)

  1. lynn eriksen says:

    The lack of IE 10 news for Windows 7 is disturbing.

  2. HTML5 & IE10 says:

    @Tony Ross and MSIE team:

    Can you publish an article about the HTML5 WebGL technology that is coming up in IE10?

    You know, we web developers just can't wait to hear about it.

  3. Julien says:

    @HTML5 & IE10

    You mean "you, web troller".

  4. AlfonsoML says:

    Thanks for the info.

    Let's see how it works when there's a beta build for Windows 7, meanwhile I'll keep using the next versions of the rest of browsers, you know, those that don't hate Windows 7 like Microsoft does.

  5. alvatrus says:

    @the troll:

    here's Microsoft's stance on webgl:

    blogs.technet.com/…/webgl-considered-harmful.aspx

  6. game kid says:

    Ah yes, the dreaded not-quite-XML responseXML.  While I was trying to make an SVG game I was experimenting with XHR to try to load other things into the game's "stage" on demand, and ran into this.

    An article on A List Apart gave a workaround to get the XML result to be properly recognized but that didn't quite fix my problems; I hope this does.

  7. Microsofts Friday July 20th Agenda says:

    Microsofts Friday July 20th Agenda

    1.) Fix the IE Blog Comment system

    2.) Post an update about full flash support in Metro without the censorship list

    3.) Windows 7 version of IE10 beta so that developers can actually test IE10 – something they can't easily do now

    4.) Publish a post regarding Metro support of other browsers – will we be able to upgrade IE10 Metro to a Metro version of Chrome or Firefox?! Especially if that is the only way businesses and users can get complete flash support

    5.) Publish an updated UserAgent string for IE10 that indicates if IE is running in Metro mode or not

    All of this should be accomplish-able by lunchtime.

  8. MS says:

    Just would like to point out to the clueless that WebGL is *not* a HTML5 standard.  It is not published by W3C.

  9. Martijn says:

    "that WebGL is *not* a HTML5 standard"

    that has never stopped MS from implementing it anyway.

  10. WebGL is an HTML5 standard says:

    The W3C isn't the only organization that creates HTML5 open specifications for the web. The HTML5 WebGL specification is published by Kronos, the same group that is also responsible for OpenGL.

    WebGL is listed as one of the HTML5 technologies on the W3C HTML5 logo page: http://www.w3.org/html/logo/

    Here's what we can read on that W3C website: "Between SVG, Canvas, WebGL, and CSS3 3D features, you're sure to amaze your users with stunning visuals natively rendered in the browser."

  11. Taylor says:

    The fact that Microsoft ever had their own version of XML (a universal markup language for arbitrary content of any kind) just goes to show you how utterly messed up Microsoft really is.

    XML is XML… there is no need for an MS version of XML aka "MSXML".

    @Developers! Seriously consider where you get your guidance on developing for the Web… obviously Microsoft is the absolute last place you should look!

  12. warrens says:

    Taylor, "MSXML" is the name of Microsoft's XML parser library, not the name of "their own version of XML" as you put it.  They followed the W3C standards of the time when implementing it, though it took them years to shake out some of the weird edge cases and solidify support for certain XML standards.

    Without MSXML, Windows wouldn't have any way of parsing XML…. and since quite a number of components of Windows rely on XML, yeah, it's actually quite needed.

  13. Taylor says:

    @warrens : "IE10 in Windows 8 Release Preview updates the responseXML from an XMLHttpRequest to return a native XML document by default."

    You either have a valid XML version 1.0 document or you don't.  It sounds like Microsoft has messed this up for years and only now finally fixed the issue.

    Only 12 years late Microsoft – well done!

  14. ieblog says:

    @Taylor: It's not about differences in the XML per se. It's that the MSXML library exposed a set of methods for operating on the XML document which are different or missing in the standardized XML DOM implementation of IE10.

  15. @WebGL is an HTML5 standard:

    >>> WebGL is listed as one of the HTML5 technologies on the W3C HTML5 logo page: http://www.w3.org/html/logo/

    Where? I can't see it.

  16. PhistucK says:

    @Maximilian Haru Raditya –

    Under the "The Technology" section, below the left box, there are eight boxes. Click on the second one to the left of the bottom row (its hover title says "3D & Effects"). To its right, it will show "WebGL" next to the others.

  17. Xero says:

    If (new XMLHttpRequest()).responseType is set to an unsupported value, it should throw an exception.

    For example;

    In the UA's console run the following code:

    (function IsArrayBufferSupported(){

       var xhr = new XMLHttpRequest();

       xhr.open('GET', '/', true);

       try{

        xhr.responseType = "arraybuffer";

        return true;

       }catch(e){return false;}

    })();

    This should return true. Which it does in IE, FF, Opera, Chrome and Safari.

    Then run:

    (function IsArrayBufferSupported(){

       var xhr = new XMLHttpRequest();

       xhr.open('GET', '/', true);

       try{

        xhr.responseType = "badValue";

        return true;

       }catch(e){return false;}

    })();

    This should return false. Which it does in Chrome (19.0.1…) and Safari (5.1.2) only. All other browsers including IE9 and 10RP return ture.

    "e.message" in both Safari and Chrome is: SYNTAX_ERR: DOM Exception 12

    In short,

    xhr.responseType = "badValue";

    should throw an exception

  18. PhistucK says:

    @Xero –

    dvcs.w3.org/…/Overview.html or http://www.w3.org/…/XMLHttpRequest do not state anywhere that an exception must/should be thrown (unless I am missing something), so, unfortunately, apparently, WebKit is doing the non standardized (sort of) thing here.

  19. Xero says:

    @PhistucK, Microsoft stated the same thing on Connect bug report that W3 may specify more responseTypes in future, which is why its open ended. Just for sake of argument, if the UA checks whether the set value is defined in the underlying engine (for example; exists in responseTypeENUM) and throw exception otherwise, it would save the run-time error. The W3 sepcs are neither enforcing nor negating this aspect, so UA vendor can rescue the erroneous code path, right?

  20. @Xero

    Except someone will depend on this. Then somewhere down the line, if a new type is added and an exception is no longer throws, you can bet that there will be at least one web site that will break and people will complain because "Microsoft broke their website".

    The w3c documentation explicitly states what it does.

    The responseType attribute must return its value. Initially its value must be the empty string.

    Setting the responseType attribute must run these steps:

    1.

    If the state is LOADING or DONE, throw an "InvalidStateError" exception and terminate these steps.

    2.

    If there is an associated XMLHttpRequest document and the synchronous flag is set, throw an "InvalidAccessError" exception and terminate these steps.

    3.

    Set the responseType attribute's value to the given value.

    Yes the way it is worded can make you think, "oh, it isn't telling me that I can't do anything else." But at the same time it isn't telling you that you can. In fact, with the way it is worded, I would interpret it more as "Setting the responseType attribute must run only these steps:".

    When working with this kind of documentation it is usually desirable to stick with exactly what it tells you to do. If you start doing anything extra then where will it end. For example, that doesn't say the UA can't format the hard disk when responseType is set, or that it can't delete all files with the .txt extension or anything like that. It doesn't even tell you that it can't go and post all of your personal data all over the internet. So really, if you want to start having exceptions thrown then you start opening yourself up to anything.

    Another example, lets take the C99 memcpy function. The description for this function is

    2 The memcpy function copies n characters from the object pointed to by s2 into the

    object pointed to by s1. If copying takes place between objects that overlap, the behavior

    is undefined.

    It doesn't tell you that your implementation can't format the hard disk too, or overwrite the rest of the process space with 0s or send all of your personal data over the internet. But there is no implementation of memcpy that does any of that. The reason why is that the interpretation of "must do this" is normally read as "must do this, and only this".

  21. Tim b. says:

    @Xero, read the last line above..

    "In theory the assignment should be ignored by other browsers, but in practice some do throw an exception. You can defend against this using a try/catch statement, as in the above example. "

    The W3 recommendation suggest that if the string doesn't makes sense to your browser, (rather than throwing nasty exception use your "brain" and) use fallback approach to the closest available responseType.

    Chrome/Safari has provided this behavior before the recommendations were published (to flash the high score on some benchmark?). This is another example when you do not wait and respect for the standards and get yourself into trouble and that being over-efficient means you are going down…

  22. Eric says:

    We have updated the release date for IE10. It looks like we will get the IE10 RTM very soonish.

    Microsoft will supposedly release Windows 8 RTM in early August. Together with the RTM release ships a copy of IE10 RTM.

  23. Jacob says:

    @Eric – OMG! Are you serious? Neither Windows 8 nor IE10 is ready for prime time! please point to your source!

    We haven't even had the IE10 Beta on Windows 7 yet! (when the f_u_d_g_e was Microsoft thinking we were going to do ALL OF OUR TESTING?!?!?)