我这段代码就是想从一个用xml做的邮件列表(4-11.xml)中提取信息其中javscript实现了下拉菜单和按钮,(书上的例子)但是不好使。请大家帮我看看!<html>
<head>
  <title>extract email</title>
   
</head>
 <body bgcolor="#ffffff">
  <xml id="messagelist" src="4-11.xml"> </xml>
<script languge="javascript">
  document.write("<h3>select the xml file to load nd then click the load file button to open it</h3>");  document.write("<br>");  document.write("SELECT Name=Select1");  RootElement1=messagelist.documentElement;  if(RootElement1==null)  {    alert("the root node is null");   document.write("<b><big>the data of the xml file  cnnot be accessed </big><b><br>");     }  else  {   nodecount=RootElement1.childNodes.length;   for(loopindex=0;loopindex<nodecount;loopindex++)   {    str1=" <OPTION ";    str1=str1+"VALUE="+RootElement1.childNodes.item(loopindex).text;    str1=str1+">"+RootElement1.childNodes.item(loopindex).text;    str1=str1+"</OPTION><BR>";    document.write(str1);   }  }  document.write("</SELECT><br>");  document.write("<FORM>");  document.write("INPUT TYPE=button Name=button1 value='click to lod file' onClick='LoadFile()'>");  document.write("</form><br>");  function LoadFile()  {    var xmlDoc1=new ActiveXObject("microsoft.xmldom");    xmlDoc1.Load(Select1 value);    if(xmlDoc1.readyState=="4")    {      var loopindex;      var RootElement1;      var nodecount;      RootElement1=xmlDoc1.documentElement;      if(RootElement1==null)      {       alert("the root node is null");       document.write("<b><big>the data of the xml file cannot be accessed</big></b><br>");             }      else       {        for(loopindex=0;loopindex<nodecount;loopindex++)         {         document.write(RootElement1.childNodes.item(loopindex).nodeName+": ");         document.write(RootElement1.childNodes.item(loopindex).text+"<br>");                 }      }          }    else    {      alert("Process could not start");          }    }    </script>
       <br>
 
</body>
</html>

解决方案 »

  1.   

    还想问一下就是在html中要写函数是不是必须用脚本亚?
      

  2.   

    必须用脚本啊.这句不对吧
      xmlDoc1.Load(Select1 value);能不能吧4-11.xml也帖出来,这样方便调试一下.==========================================
    欢迎使用 Forums Helper 论坛助手...      [助您多、快、好、爽上CSDN...]
    语法高亮、发贴、回帖、浏览、搜索、论坛短信、监视更新、自动签名、本地另存!速度极快!
    程序最后更新2004年07月13日   [Powered By ChinaOK]
      

  3.   

    _____________4-11.xml______
    <?xml version="1.0" ?>
    <MESSAGELIST>
    <MESSAGE>4-7.xml</MESSAGE>
    <MESSAGE>4-8.xml</MESSAGE>
    <MESSAGE>4-9.xml</MESSAGE>
    <MESSAGE>4-10.xml</MESSAGE>
    </MESSAGELIST>
    _________________4-7.xml__________
    <?xml version="1.0" ?>
    <MESSAGE>
    <FILENAME>4-7.xml</FILENAME>
    <TO>Author</TO>
    <FROM>student</FROM>
    <SUBJECT>xml code islands</SUBJECT>
    <body>this is a reply to your message about xml data islands. </body>
    </MESSAGE>4-8, 4-9, 4-10 差不多。下面是改动后的4-12,还是不对_________________________4-12________________
    <html>
    <head>
    <title>extract email</title>
       
    </head>
    <body bgcolor="ffffff">
    <script languge="JavaScript">
    document.write("<h3>select the xml file to load nd then click the load file button to open it</h3>");
    </script>
    <xml id=messagelist src="4-11.xml">   </xml> 
    <script languge="JavaScript">
      document.write("<h3>select the xml file to load nd then click the load file button to open it</h3>");  document.write("<br>");  document.write("<select Name=Select1>");  RootElement1=messagelist.documentElement;  if(RootElement1==null)  {    alert("the root node is null");   document.write("<b><big>the data of the xml file  cnnot be accessed </big></b><br>");     }  else  {   nodecount=RootElement1.childNodes.length;   for(loopindex=0;loopindex<nodecount;loopindex++)   {    str1=" <OPTION ";    str1=str1+"VALUE="+RootElement1.childNodes.item(loopindex).text;    str1=str1+">"+RootElement1.childNodes.item(loopindex).text;    str1=str1+"</OPTION><BR>";    document.write(str1);   }  }  document.write("</select><br>");  document.write("<form>");  document.write("<INPUT TYPE="button" Name="button1" value="click to load file" onClick="LoadFile()">");  document.write("</form><br>"); function LoadFile()  {    var xmlDoc1=new ActiveXObject("microsoft.xmldom");    xmlDoc1.Load(Select1.value);    if(xmlDoc1.readyState=="4")    {      var loopindex;      var RootElement1;      var nodecount;      RootElement1=xmlDoc1.documentElement;      if(null==RootElement1)      {       alert("the root node is null");       document.write("<b><big>the data of the xml file cannot be accessed</big></b><br>");             }      else       {        for(loopindex=0;loopindex<nodecount;loopindex++)         {         document.write(RootElement1.childNodes.item(loopindex).nodeName+": ");         document.write(RootElement1.childNodes.item(loopindex).text+"<br>");                 }      }          }    else    {      alert("Process could not start");          }    }
    </script>
    </body>
    </html>
      

  4.   

    江湖救急,难道csdn上没人懂了吗??
      

  5.   

    <html>
    <head>
    <title>extract email</title>
       
    </head>
    <body bgcolor="ffffff">
    <script languge="JavaScript">
    document.write("<h3>select the x button to open it</h3>");
    </script>
    <xml id=messagelist src="4-11.xml"></xml> 
    <script languge="JavaScript">
      document.write("<h3>select the xml file to load nd then click the load file button to open it</h3>");  document.write("<br>");
      document.write("<form name=\"Form1\">");
      document.write("<select Name=Select1>");
      document.write("<OPTION VALUE='' Selected='true' >请选择 </OPTION>");  var RootElement1=messagelist.documentElement;  if(RootElement1==null)  {    alert("the root node is null");   document.write("<b><big>the data of the xml file  cnnot be accessed </big></b><br>");     }  else  {   nodecount=RootElement1.childNodes.length;
       for(loopindex=0;loopindex<nodecount;loopindex++)   {    str1=" <OPTION ";    str1=str1+"VALUE="+RootElement1.childNodes.item(loopindex).text;    str1=str1+">"+RootElement1.childNodes.item(loopindex).text;    str1=str1+"</OPTION>";    document.write(str1);   }  }  document.write("</select><br>");  document.write("<INPUT TYPE=\"button\" Name=\"button1\" value=\"click to load file\" onClick=\"LoadFile()\">");  document.write("</form><br>"); function LoadFile()  {
    var files=document.Form1.Select1.options[document.Form1.Select1.selectedIndex].value;

        var xmlDoc1=new ActiveXObject("microsoft.xmldom");    xmlDoc1.load(files);    if(xmlDoc1.readyState=="4")    {      var loopindex;      var RootElement1;      var nodecount;
      var strCollection;      RootElement1=xmlDoc1.documentElement;      if(null==RootElement1)      {       alert("the root node is null");       //document.write("<b><big>the data of the xml file cannot be accessed</big></b><br>");             }      else       {  strCollection = "";
     nodecount=RootElement1.childNodes.length;
      
            for(loopindex=0;loopindex<nodecount;loopindex++)         {
    //一旦整个网页解析显示完毕,就不能在write了,只能通过innerHTML,,innerText来改变内容.所以以下代码是错误的.
             //document.write(RootElement1.childNodes.item(loopindex).nodeName+": ");         //document.write(RootElement1.childNodes.item(loopindex).text+"<br>");
    strCollection += RootElement1.childNodes.item(loopindex).nodeName+": ";
    strCollection += RootElement1.childNodes.item(loopindex).text+"<br> ";                 }
           vi.innerHTML = strCollection;
      // alert(strCollection);
           
          }          }    else    {      alert("Process could not start");          }    }
    </script><DIV ALIGN="center" Id="vi" ></DIV>
    </body>
    </html>
      

  6.   

    ChinaOk(农村表哥)
    谢谢你!
    你上面给出的程序,我运行了一下, 并不是很理想,没有按钮 候选下拉菜单中也没有
    4-x.xml文件,只有一个没选择。也可能使我的环境有问题。
    我的操作系统是windows 2003 浏览器是IE 6.0  & netscape 7.0
    好多东西IE 6.0 都不显示

    请问一下你的qq和你的email,请你帮我再看看。
    搞定后一定多多给分,可以交个朋友嘛?
      

  7.   

    忘了,我的qq:55924693
              email: [email protected]