0

使用 javascript 解析 xml_file 时缺少数据。我正在尝试使用 HTML 和 Javascript 从 web 浏览器中的 xml 文件显示第一个孩子。问题是,第一个孩子的名字没有出现。注意:我使用的是谷歌浏览器。 在此处输入图像描述 Javascript:

     <title>Read First Child</title>
        <xml ID="Schriftsteller" SRC="D:\files\files\Schriftsteller.xml"></xml>
           <script language="JavaScript">

           function loadXMLDoc("D:\files\files\javascriptparser.html")
              {
                 var xmlDoc;
                 if (window.XMLHttpRequest)
                 {
                  xmlDoc=new window.XMLHttpRequest();
                  xmlDoc.open("GET","D:\files\files\javascriptparser.html",false);
                  xmlDoc.send("");
                  return xmlDoc.responseXML;
                 }
                 // IE 5 and IE 6
                  else if (ActiveXObject("Microsoft.XMLDOM"))
                  {
                   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                   xmlDoc.async=false;
                   xmlDoc.load(XMLname);
                   return xmlDoc;
                  }
                    alert("Error loading document!");
                    return null;
              }

              function findWriter() 
              {
                 var Schriftsteller, schriftstellerKnoten, SpracheKnoten;
                 var FüllerKnoten, DichtungKnoten, Anzeige;

                 myXML = document.all("D:\files\files\Schriftsteller.xml").XMLDocument;
                 SchriftstellerKnoten = myXML.documentElement;
                 SpracheKnoten = SchriftstellerKnoten.firstChild;
                 DichtungKnoten = SpracheKnoten.firstChild;
                 FüllerKnoten = DichtungKnoten.firstChild;
                 NameNode = FüllerKnoten.firstChild;
                 Anzeige = NameNode.firstChild.nodeValue;
                 Documentar.show.me.value = Anzeige;
              }
           </script>
               <span ID="blueBack">Read firstChild</span>
               <div>
               <form name="show">
               <input type=text name="me">
               <input type="button" value="Display Writer"
                onClick="findWriter()">
               </form>
               </div>
               </body>

4

1 回答 1

0

xmlDoc.open("GET",D:\files\files\javascriptparser.html,false);

这是您使用的语句。文件的路径是一个字符串。它应该用引号括起来,如下所示:

xmlDoc.open("GET","D:\files\files\javascriptparser.html",false);

于 2013-07-22T11:49:47.233 回答