我是编程新手,目前正在尝试简单地列出XML页面中的所有内容并将其输出到HTML页面上。 我阅读了一下,发现可以使用xmlDoc来完成,所以我一直在玩。
我目前有以下内容;
<!DOCTYPE html>
<html>
<body>
<p id="title"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "http://myurl.com/list.xml", true);
xhttp.send();
function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('title');
for (i = 0 ; i <x.length; i++) {
txt += x[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("title").innerHTML = txt;
}
</script>
</body>
</html>
这很好用,但是我目前仅列出一个标签..标题。 现在如何添加更多我感兴趣的标签?我目前正在学习,但遇到困难,我需要以某种方式在txt变量中获取这些额外的标签。
xml文件结构是;
<entry>
<title></title>
<link></title>
<id></id>
<published></<published>
<updated></updated>
</entry>
感谢您的帮助。