function importXML()
{
 if (document.implementation && document.implementation.createDocument)
 {
  xmlDoc = document.implementation.createDocument("", "", null);
  xmlDoc.onload = createTable;
 }
 else if (window.ActiveXObject)
 {
  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.onreadystatechange = function () {
   if (xmlDoc.readyState == 4) createTable()
  };
  }
 else
 {
  alert('Your browser can\'t handle this script');
  return;
 }
 xmlDoc.load("D:\emperors.xml");
}
function createTable()
{
 var x = xmlDoc.getElementsByTagName('emperor'); //**************
    var a=x[0].childNodes[0].nodeName;
 var b=x[0].childNodes[0].firstChild.nodeValue;
 x[0].childNodes[0].firstChild.nodeValue="123";
 alert(a);
 alert(b);
 //**************
 var newEl = document.createElement('TABLE');
 newEl.setAttribute('cellPadding',5);
 var tmp = document.createElement('TBODY');
 newEl.appendChild(tmp);
 var row = document.createElement('TR');
 for (j=0;j<x[0].childNodes.length;j++)
 {
  if (x[0].childNodes[j].nodeType != 1) continue;
  var container = document.createElement('TH');
  var theData = document.createTextNode(x[0].childNodes[j].nodeName);
  container.appendChild(theData);
  row.appendChild(container);
 }
 tmp.appendChild(row);
 for (i=0;i<x.length;i++)
 {
  var row = document.createElement('TR');
  for (j=0;j<x[i].childNodes.length;j++)
  {
   if (x[i].childNodes[j].nodeType != 1) continue;
   var container = document.createElement('TD');
   var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
   container.appendChild(theData);
   row.appendChild(container);
  }
  tmp.appendChild(row);
 }
 document.getElementById('ABc').appendChild(newEl);
}  <br>
<input type="button" name="AB" value="aaaa" onClick="importXML()">
<div id="ABc">
</div>

解决方案 »

  1.   

    什么是 JScript?
    JScript 是 Microsoft 公司对 ECMA 262 语言规范(ECMAScript 编辑器 3)的一种实现。除了少数例外(为了保持向后兼容),JScript 完全实现了 ECMA 标准。本概述的目的就是引导您学习使用 JScript。要在 JScript 中使用这种方法来创建文本文件,则使用下面的代码:var fso, ts;
    var ForWriting= 2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true);
      

  2.   

    楼上的大哥,这要求XML文件怎样的格式,有示范吗
      

  3.   

    你使用这种方式,ie自带的功能,比较实用,或许你能用得上!
    <IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
    <body onload="oDownload.startDownload('new.xml',onDownloadDone)">
    <span id=showImport></span>
    <script language=javascript><!--
    function onDownloadDone(downDate)
    {
      alert(downDate); //这种方法被讨论出来是最好的

    </script>