English 中文(简体)
Sato Won t Work with Morgan.XMLDOM 活性X
原标题:Safari Won t Work With Microsoft.XMLDOM ActiveX Object

I m 设计一个用户侧面文字,读作XML文档并显示:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

function loadXML(xmlFile) {
    xmlDoc.async = "false";
    xmlDoc.onreadystatechange = verify;
    xmlDoc.load(xmlFile);
}

function verify() {
    if(xmlDoc.readyState != 4) {
        return false;
    }
}

function traverse(tree) {
    if(tree.hasChildNodes()) {
        document.write( <ul><li> );
        document.write( <b>  + tree.tagName +  : </b> );
        var nodes = tree.childNodes.length;

        for(var i = 0; i < tree.childNodes.length; i++) {
            traverse(tree.childNodes(i));
        }
        document.write( </il></ul> );
    } else {
        document.write(tree.text);
    }
}

function initTraverse(file) {
    loadXML(file);
    var doc = xmlDoc.documentElement;
    traverse(doc);
}

当我向Safari I开枪时,我看到没有显示任何东西,然后,我就宣布Error Console,我是:

参考资料: t 活性XO 目标

我应该做些什么来做这项工作?

PS:如果能够在移动电话<<>上运行,我更愿意这样做。

最佳回答

那里有一些令人感兴趣的问题。 最为有趣的是async = 虚假。 也许,你想重新考虑这一界限。 为了改变要求,你必须重新制定其他守则,删除<条码>文件<>。

不管怎样,这里(未经测试但充满希望的)是你使用XMLHttpRequest而不是Xml文件的替代物。

var xmlDoc = null;
function loadXML(xmlFile) {
  var request = new XMLHttpRequest();
  request.open( GET , xmlFile, false); // false is synchronous
  request.send();

  xmlDoc = request.responseXML;
}

您可能不得不做一些偷盗......

问题回答

活性XObject在互联网探索者之外工作。

有几个替代的Xml parser和操作器,例如E4X。 虽然E4X目前只在大火中进行(https://developer.mozilla.org/En/E4X/Processing_XML_with_E4X)。

如果使用 j子是一种选择,那么你就能够看看一看 mar子。

你们应当拥有一些与DOMParser或OMDocument相容的交叉浏览器。 当然,我不敢肯定,你是否想要打上XML URL或XML的扼杀。 我建议:

  if      (window.XMLHttpRequest) return new window.XMLHttpRequest();
  else if (window.ActiveXObject) {
     // the many versions of IE s XML fetchers
     var AXOs = [
         MSXML2.XMLHTTP.6.0 ,
         MSXML2.XMLHTTP.5.0 ,
         MSXML2.XMLHTTP.4.0 ,
         MSXML2.XMLHTTP.3.0 ,
         MSXML2.XMLHTTP ,
         Microsoft.XMLHTTP ,
         MSXML.XMLHTTP 
     ];
     for (var i = 0; i < AXOs.length; i++) {
        try     { return new ActiveXObject(AXOs[i]); }
        catch() { continue; }
     }
     return null;
  }

对于XML的扼杀,这套法典将更好地发挥作用:

    if      (window.DOMParser)     return (new DOMParser()).parseFromString(str,  text/xml );
    else if (window.ActiveXObject) {
        var doc;

        // the many versions of IE s DOM parsers
        var AXOs = [
             MSXML2.DOMDocument.6.0 ,
             MSXML2.DOMDocument.5.0 ,
             MSXML2.DOMDocument.4.0 ,
             MSXML2.DOMDocument.3.0 ,
             MSXML2.DOMDocument ,
             Microsoft.XMLDOM ,
             MSXML.DOMDocument 
        ];
        for (var i = 0; i < AXOs.length; i++) {
            try     { doc = new ActiveXObject(AXOs[i]); break; }
            catch() { continue; }
        }    
        if (!doc) return createElement( div , null);

        if (doc.async) doc.async = false;
        doc.loadXML(str);
        return doc;
    }
    return createElement( div , null);

The DOMDocument objects do support a load() method for loading XML from a URL, but it s a different syntax than the XMLHttpRequest and XMLHTTP methods.

DOMDocument(至少从MSDN docs中)似乎也含有XMLHTTP方法,因此,你可以把DOMDocument列入CAROs阵列,但我对此并不肯定。 此外,我可以想象在没有XMLHTTP的情况下建立了多功能文件。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签