繁体   English   中英

使用javascript读取本地XML文件并显示在html页面中

[英]Reading local XML file using javascript and display in html page

我正在尝试通过javascript读取xml文件并将其显示在HTML页面中。

我正在使用以下代码。

function readxml() {
alert("calledreadxml");
var myXML, studentnode;    
myXML= document.all("config.xml").XMLDocumentalert(myXML);
studentnode = myXML.documentElement
var string;
var nxtnode;
while(nxtnode)
{
    string = "the value of "+nxtnode.nodeName+"is :"+ nxtnode.nodeValue+"\n";
    nxtnode = myXML.nextSibling;
}
}

该代码无法正常工作..任何人都可以帮忙

<script type="text/javascript">

                           if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                               xmlhttp = new XMLHttpRequest();
                           }
                           else {// code for IE6, IE5
                               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                           }
                           xmlhttp.open("GET", "Images-Info.xml", false);
                           xmlhttp.send();
                           xmlDoc = xmlhttp.responseXML;


                                                   var x = xmlDoc.getElementsByTagName("Image_Store");

                           for (i = 0; i < x.length; i++) 
                           {
                              var type = x[i].getElementsByTagName("Image_Type")[0].childNodes[0].nodeValue;
                               var title = x[i].getElementsByTagName("Image_Title")[0].childNodes[0].nodeValue;
                              var des = x[i].getElementsByTagName("Image_Description")[0].childNodes[0].nodeValue;
                               var ph = x[i].getElementsByTagName("Image_Photo")[0].childNodes[0].nodeValue;
                               var thm = x[i].getElementsByTagName("Thumbnail_Photo")[0].childNodes[0].nodeValue;
                              // Ul1.innerHTML = Ul1.appendChild("<li><div><a  href=\"" + ph + "\" \><img src=\"" + thm + "\" \/></a><p>" + title + "</p></div><div class=\"data\"><div><h1>" + title + "</h1>" + des + "</div></div></li>");
                               document.write("<li>");
                               document.write("<div>");
                               document.write("<a  href=\"" + ph + "\" \>");
                               document.write("<img src=\"" + thm + "\" \/>");
                               document.write("</a>");
                               document.write("<p>");
                               document.write(title);
                               document.write("</p>");
                               document.write("</div>");
                               document.write("<div class=\"data\">");
                               document.write("<div>");
                               document.write("<h1>");
                               document.write(title);
                               document.write("</h1>");
                               document.write(des);
                               document.write("</div>");
                               document.write("</div>");
                               document.write("</li>");
                           }                
        </script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM