Native XML object types and legacy websites

Windows Internet Explorer 9 introduces the concept of native XML objects. Native XML objects can be rendered within a page and used with the same Document Object Model (DOM) APIs supported for HTML objects. Prior versions of Windows Internet Explorer always managed XML via Microsoft XML (MSXML) objects, which still exist in Internet Explorer 9. However, native XML objects are not compatible with MSXML objects. This means that MSXML objects cannot be used with native DOM APIs and native XML objects cannot be used with MSXML DOM APIs.

When the code in a site attempts to mix the two, this generally results in a JavaScript exception being thrown, which can cause compatibility problems.

Passing a node obtained from responseXML (which returns an MSXML object) into a native DOM API is the most likely scenario in which this happens.

var doc = xhr.responseXML;
if(document.adoptNode) document.adoptNode(doc.documentElement);

Most sites already have fallback code to correctly handle MSXML objects, but the problem occurs when certain feature detects cause sites to attempt to use native DOM APIs. The most common detects that cause problems are:

  • Update site code to work entirely with native objects and APIs or MSXML objects and APIs

  • In general, try to migrate to native objects and APIs unless you need features like XPath/XSLT; this can be done by passing responseText to DOMParser, instead of using responseXML var:

    parser = new DOMParser();
    parser.parseFromString(xhr.responseText, "text/xml");
  • If MSXML APIs are still required, feature checks can be updated to verify the type of node received in order to select the correct API:

    if(!window.Node || !(node instanceof Node)) {
      // This is an MSXML node