<html>
<head>
<link rel="stylesheet" type="text/css" href="airport.css" />
<script type="text/javascript"> function readXML() {
var paraText;
var newRow;
var newPara;
var newCell;
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("Aanda.xml");
displayAirportsAirlines();
}
else if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load("Aanda.xml");
xmlDoc.onload = displayAirportsAirlines;
}
else {
throw new Error("XML load is not supported by this browser");
}
};
function displayAirportsAirlines() { var units = xmlDoc.getElementsByTagName("location")
var theTable = document.getElementById("unittable")
var theTableBody = document.createElement("tbody") for (var i = 0; i < units.length; i++) //for each unit element
{
newRow = document.createElement("tr") //create a new table row
paraText = document.createTextNode(units[i].getElementsByTagName("airport")[0].firstChild.nodeValue)
newPara = document.createElement("p") //create an empty paragraph element
newPara.appendChild(paraText) //add text to paragraph element
newCell = document.createElement("td") //create a new table cell
newCell.appendChild(newPara) //add paragraph element to table cell
newRow.appendChild(newCell) //add cell to table row
paraText = document.createTextNode(units[i].getElementsByTagName("code")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body paraText = document.createTextNode(units[i].getElementsByTagName("telephone")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body paraText = document.createTextNode(units[i].getElementsByTagName("address")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body
}
theTable.appendChild(theTableBody) //add table body to table
}
</script>
<title>Airports and Airlines</title>
</head>
<body onload="readXML()">
<h1>
Airports and Airlines information</h1>
<table id="unittable" width="1240px" bgcolor="#a0a0a0" border="8px">
<tr>
<th>
airport
</th>
<th>
code
</th>
<th>
tel
</th>
<th>
adress
</th>
</tr>
</table>
</body>
</html>
这样的话只显示的我XML location 下的第一个airport
我的location的定义是<location type="South West--10 airports">
一共有9个type
怎么样可以让他们都显示出来?
<head>
<link rel="stylesheet" type="text/css" href="airport.css" />
<script type="text/javascript"> function readXML() {
var paraText;
var newRow;
var newPara;
var newCell;
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("Aanda.xml");
displayAirportsAirlines();
}
else if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load("Aanda.xml");
xmlDoc.onload = displayAirportsAirlines;
}
else {
throw new Error("XML load is not supported by this browser");
}
};
function displayAirportsAirlines() { var units = xmlDoc.getElementsByTagName("location")
var theTable = document.getElementById("unittable")
var theTableBody = document.createElement("tbody") for (var i = 0; i < units.length; i++) //for each unit element
{
newRow = document.createElement("tr") //create a new table row
paraText = document.createTextNode(units[i].getElementsByTagName("airport")[0].firstChild.nodeValue)
newPara = document.createElement("p") //create an empty paragraph element
newPara.appendChild(paraText) //add text to paragraph element
newCell = document.createElement("td") //create a new table cell
newCell.appendChild(newPara) //add paragraph element to table cell
newRow.appendChild(newCell) //add cell to table row
paraText = document.createTextNode(units[i].getElementsByTagName("code")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body paraText = document.createTextNode(units[i].getElementsByTagName("telephone")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body paraText = document.createTextNode(units[i].getElementsByTagName("address")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow) //add row to table body
}
theTable.appendChild(theTableBody) //add table body to table
}
</script>
<title>Airports and Airlines</title>
</head>
<body onload="readXML()">
<h1>
Airports and Airlines information</h1>
<table id="unittable" width="1240px" bgcolor="#a0a0a0" border="8px">
<tr>
<th>
airport
</th>
<th>
code
</th>
<th>
tel
</th>
<th>
adress
</th>
</tr>
</table>
</body>
</html>
这样的话只显示的我XML location 下的第一个airport
我的location的定义是<location type="South West--10 airports">
一共有9个type
怎么样可以让他们都显示出来?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货