views:

390

answers:

1

I'm using Safari for windows. It tells me that document.prototype.loadXML is undefined. What are my other options to create XML document?

A: 

From http://www.w3schools.com/Xml/xml_parser.asp (reformatted a bit):

The following code loads and parses an XML string:

function loadXML(text)
{
    var xmlDocument = null;

    // Internet Explorer
    try
    {
        xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
        xmlDocument.async = false;
        xmlDocument.loadXML(text);
    }
    // Standards-compliant method.
    catch (exception)
    {
        parser      = new DOMParser();
        xmlDocument = parser.parseFromString(txt, "text/xml");
    }

    return xmlDocument;
}

Note: Internet Explorer uses the loadXML() method to parse an XML string, while other browsers use the DOMParser object.

John Kugelman