错误整理 XML文件读取

xml 代码
  1. xx.xml   
  2.     
  3.  <test>  
  4.     <li>1li>  
  5.     <li>hahahahahahali>  
  6.     <li>3li>  
  7.     <li>4li>  
  8.  test>  
Html 代码
  1. <html>  
  2.    <head>  
  3.      <script language="javascript">  
  4.        var xmlHttp;   
  5.     
  6.        function createXMLHttpRequest(){   
  7.          if(window.ActiveXObject){   
  8.             xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
  9.          }else if(window.XMLHttpRequest){   
  10.             xmlHttp = new XMLHttpRequest();     
  11.          }   
  12.        }   
  13.           
  14.        function startRequest(){   
  15.             
  16.          createXMLHttpRequest();   
  17.          xmlHttp.onreadystatechange = test;   
  18.          xmlHttp.open("GET","xx.xml",true);   
  19.          xmlHttp.send(null);   
  20.        }   
  21.           
  22.        function test(){   
  23.             
  24.             if(xmlHttp.readyState == 4){   
  25.                if(xmlHttp.status == 200){   
  26.                     
  27.                  var xmlTest = xmlHttp.responseXML;   
  28.                  var tagTest = xmlTest.getElementsByTagName("test")[0];   
  29.                  var childTag = tagTest.getElementsByTagName("li");   
  30.                  document.form1.t1.value = childTag[1].firstChild.nodeValue;   
  31.           document.form1.t2.value = childTag[2].firstChild.nodeValue;   
  32.           document.form1.t3.value = childTag[3].firstChild.nodeValue;   
  33.                }   
  34.             }   
  35.                  
  36.            
  37.        }   
  38.      script>  
  39.    head>  
  40.    <body>  
  41.       <form name="form1" action="">  
  42.         <input type="text" name="t1"/>  
  43.         <input type="text" name="t2"/>  
  44.         <input type="text" name="t3"/>  
  45.         <input type="button" value="tttt" onClick="startRequest()"/>  
  46.       form>  
  47.    body>  
  48. html>  

你可能感兴趣的:(JavaScript,html,xml,Microsoft)