2010-02-24 3 views
0

Javascript를 사용하여 XML 파일을 구문 분석하려고하는데 IE7에서 문제가 발생합니다.Javascript를 사용하여 IE에서 XML을로드 할 때 루트 노드가 검색되지 않습니다.

이 코드가있는 경우 : FF에서

function LoadXml() 
{ 
    var xmlPath = document.getElementById("hsTreeviewXmlPath").value; 

    var xmlhttp=false; 
    /*@cc_on @*/ 
    /*@if (@_jscript_version >= 5) 
    // JScript gives us Conditional compilation, we can cope with old IE versions. 
    // and security blocked creation of the objects. 
    try { 
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
     alert("here1"); 
    } catch (e) { 
     try { 
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     alert("here2"); 
     } catch (E) { 
     xmlhttp = false; 
     } 
    } 
    @end @*/ 
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
     try { 
      xmlhttp = new XMLHttpRequest(); 
      alert("here3"); 
     } catch (e) { 
      xmlhttp=false; 
     } 
    } 
    if (!xmlhttp && window.createRequest) { 
     try { 
      xmlhttp = window.createRequest(); 
      alert("here4"); 
     } catch (e) { 
      xmlhttp=false; 
     } 
    } 

    xmlhttp.open("GET",xmlPath,false); 
    xmlhttp.send(null); 

    var xmlDoc = xmlhttp.responseXML; 

    ParseXml(xmlDoc); 
} 

function ParseXml(xmlDoc) 
{ 
    var root = xmlDoc.documentElement; 
    alert(root); 

    for(i=0; i< root.childNodes.length; i++) 
    { 
     var node = root.childNodes[i]; 
     if(node.nodeType ==1) //process element nodes (type 1) 
     { 
      if(node.childNodes.length > 1) 
      { 
       CreateChildren("hsTreeview",node); 
      } 
      else 
      { 
       AddNode("hsTreeview", node); 
      } 
     } 
    } 
} 

을하고 정상적으로 크롬이 노드를 추가, 제대로 작동하지만 IE7에 내가 스크립트 오류 및 특정 오류 얻을 :

Object required

이 라인에 관련된 행 번호 제공 :

for(i=0; i< root.childNodes.length; i++) 
{ 

경고 상자가 나에게 이야기를 IE에서, 일이 e xmlDoc.documentElement에서 채워지는 루트 노드가 null입니다.

나는 IE7에서는 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 개체를 사용하고 있다는 경고 등을 사용하여 확인했습니다.

정말 실망 스럽기 때문에이 문제를 해결할 수있는 방법이 있습니까?

답변

1

XML 파일이 적절한 text/xml Mime 유형과 함께 제공되는지 확인하십시오.

편집 우는 소리 :

는 또한 XML 파일이 동일한 도메인 및 웹 페이지와 포트에서 HTTP 서버를 통해 제공되어 있는지 확인합니다. IE는 보안상의 이유로 웹 페이지가 원래 도메인 외부의 URL이나 로컬 컴퓨터의 파일에 액세스하는 것을 차단합니다.

+0

어떻게 그렇게하나요? 이 파일은 Sharepoint 디렉토리에있는 파일입니다. 테스트 케이스 (HDD 제외)에서는 여전히 작동하지 않습니다. –

+0

@Alastair 확장자가 .xml 인 파일을 'var xmlPath'로 이름을 바꾸고 http를 통해 웹 페이지를로드 할 수 있습니까? –

+0

파일이 XML 파일로 지정되면 경로는 ".xml"로 끝납니다. http를 통해로드하면 정확히 무엇을 의미합니까? –

관련 문제