0

我需要在 HTML 文件中显示 XML 文件。cookie 告诉它它在哪个文件夹中。

    var username = getCookie("username"),
    docUrl = "http://officedocs.freeserver.me/userdata/" + username + "/docs.xml",
    xmlhttp, xmlDoc, finalStr, x, i;

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", docUrl, false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML; 

finalStr = "<div class='well'><table>";
x = xmlDoc.getElementsByTagName("document");
for (i = 0; i < x.length; i++) { 
    finalStr += "<tr><td>";
    finalStr += "<img src='toolbar_documents.png'/>";
    finalStr += "</td><td>";
    finalStr += "<a href='" + x[i].getElementsByTagName("url")[0].childNodes[0].nodeValue + "'>";
    finalStr += x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
    finalStr += "</a></td></tr>";
}
finalStr += "</table>";
document.write(finalStr);

继承人的XML:

<document>
<name>New Document</name>
<url>http://example.com</url>
</document>

它不会写入 XML 文件,它可能是document变量,

为什么不写呢?

4

0 回答 0