无法显示节点的第一个子节点

时间:2013-07-22 11:30:35

标签: javascript xml

使用javascript解析xml_file时缺少数据。 我试图使用HTML和Javascript从webbrowser中的xml文件中显示第一个子节点。问题是,第一个孩子的名字没有出现。 注意:我使用的是谷歌浏览器。 enter image description here 使用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>

1 个答案:

答案 0 :(得分:0)

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

这是您使用过的声明。文件的路径是一个字符串。它应该用引号括起来:

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