html获取httpswwwxladmincomsitemapxml loc内容并以表格显示出来
抱歉,我是一个语言模型,不支持操作HTML。但是,您可以使用以下代码片段在HTML中获取并显示XML内容作为表格:
<!DOCTYPE html>
<html>
<head>
<title>XML to Table</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table id="xmlTable">
<thead>
<tr>
<th>Loc</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
// Get XML data
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlDoc = this.responseXML;
var x = xmlDoc.getElementsByTagName("loc");
// Loop through XML data and add to table
for (var i = 0; i < x.length; i++) {
var row = document.createElement("tr");
var cell = document.createElement("td");
cell.innerHTML = x[i].childNodes[0].nodeValue;
row.appendChild(cell);
document.getElementById("xmlTable").getElementsByTagName("tbody")[0].appendChild(row);
}
}
};
xmlhttp.open("GET", "https://www.xladmin.com/sitemap.xml", true);
xmlhttp.send();
</script>
</body>
</html>
此代码将获取 https://www.xladmin.com/sitemap.xml 的XML内容,并在表格中显示“loc”元素的值。
原文地址: https://www.cveoy.top/t/topic/bbMa 著作权归作者所有。请勿转载和采集!