Safari testcase | document.load

The load method of a Document object should be implemented. What's the use in a web-page of document.implementation.createDocument anyway, if the load method is not implemented.

This testcase discusses in what way the load method is used in conjunction with createDocument on the web. The first two scripts will fail, because the load propery is undefined in Safari. The third script is the way it should be implemented.

This script will fail in Safari (but you won't notice).

function ()
{
  if (document.implementation&&document.implementation.createDocument)
  {
    xmlDoc = document.implementation.createDocument('','',null);
    xmlDoc.onload = function() { alert('loaded'); };
    xmlDoc.load('apple.xml');
  }
  else 
  {
    alert('Sorry, no support for Document.load');
  }
}

This script will fail in Safari (you will get an alert).

function ()
{
  try
  {
    if (document.implementation&&document.implementation.createDocument)
    {
      xmlDoc = document.implementation.createDocument('','',null);
      xmlDoc.onload = function() { alert('loaded'); };
      xmlDoc.load('apple.xml');
    }
    else 
    {
      alert('Sorry, no support for Document.load');
    }
  }
  catch(ex)
  {
    alert('Exception: '+ex);
  }
}

This is how it should be programmed.

function ()
{
  if (document.implementation&&document.implementation.createDocument)
  {
    xmlDoc = document.implementation.createDocument('','',null);
    xmlDoc.onload = function() { alert('loaded'); };
    if(xmlDoc.load)
    {
      xmlDoc.load('apple.xml');
    }
    else
    {
      alert('Sorry, no support for Document.load (2)');
    }
  }
  else 
  {
    alert('Sorry, no support for Document.load (1)');
  }
}

But really, a way of loading XML documents would really come in handy ;-)


Back to the bugs