我正在开发一个应用程序,点击按钮时,程序调用存储在XML文件中的信息,以使用JavaScript在<span>
标记中显示;解析XML文件不起作用
function viewXMLFiles() {
console.log("viewXMLFiles() is running");
var xmlhttp = new HttpRequest();
xmlhttp.open("GET", "TestInfo.xml", false);
xmlhttp.send;
console.log("still running");
var xmlDoc = xmlhttp.responseXML;
console.log("getting tired");
document.getElementById("documentList").innerHTML = xmlDoc.getElementByTagName("documentList")[0].childNodes[0].nodeValue;
document.getElementById("documentList").innerHTML = xmlDoc.getElementByTagName("documentList")[1].childNodes[1].nodeValue;
console.log("done");
}
然后调用它的HTML是(以及将显示XML文件的位置);
<button onclick = "viewXMLFiles();">View Document Info</button><br>
<span id = "documentList">
<!--This is where the XML will be loaded into-->
</span>
该XML文件是;
<document_list>
<document>
<document_name>Holidays.pdf</document_name>
<file_type>.pdf</file_type>
<file_location></file_location>
</document>
<document>
<document_name>iPhone.jsNotes.docx</document_name>
<file_type>.docx</file_type>
<file_location></file_location>
</document>
</document_list>
在控制台中,出现第一条消息,但没有任何反应,这就是所有的结果。但我真的(如,真的新)到XML和解析,并不明白是什么错。你能帮忙吗?
您是否尝试过使用XMLHttpRequest? – Marek 2013-03-20 11:58:15
我说'新的HttpRequest'? – 2013-03-20 11:59:17
好吧我试过了,现在它打破了'document.getElementById'行 – 2013-03-20 12:00:39