我正在開發一個應用程序,點擊按鈕時,程序調用存儲在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