怎样把两个xml文件都在一个html网页上显示出来呢?我写的只会执行最后一个。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>Product List: </h1>
<p id="categories"></p >
<p id="products"></p >
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
} };
xhttp.open("GET", "categories.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var txt = "";
x = xmlDoc.getElementsByTagName("Categories")[1];
var categories = get_categories(x);
document.getElementById("categories").innerHTML = categories.nodeName;
document.getElementById("categories").innerHTML = "categories: " + categories.nodeName + " " + categories.firstChild.nodeValue;
return categories;
}
function get_categories(n){
var y = n.firstChild;
while (y.nodeType !=1){
y = y.nextSibling;
}
return y;
}
</script>
<script>
var xhttpx = new XMLHttpRequest();
xhttpx.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
myFunction(this);
}
}
xhttpx.open("GET", "products.xml",true);
xhttpx.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var txt = "";
x = xmlDoc.getElementsByTagName("Products")[1];
var products = get_products(x);
document.getElementById("products").innerHTML = products.nodeName;
document.getElementById("products").innerHTML = "products: "+ products.nodeName + " " +products.firstChild.nodeValue;
return products;
}
function get_products(n){
var z = n.lastChild;
while (z.nodeType !=1) {
z = z.previousSibling;
}
return z;
}
</script>
</body>
</html>