sách gpt4 ăn đã đi

javascript - 使用 javascript 在 HTML 中显示 XML 数据

In lại Tác giả: Walker 123 更新时间:2023-11-30 17:41:40 26 4
mua khóa gpt4 giày nike

您好,目前我有以下 XML 文件和我的脚本。













if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
khác
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","ResourceList.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

document.write("");

var x=xmlDoc.getElementsByTagName("ResourceGroup");
for (i=0;i<>
{
document.write("
");
document.write(x[i].getElementsByTagName("ResourcesInfo")[0].childNodes[0].nodeValue);
}
document.write("
");

谁能帮忙??我按照 w3school 中的示例并尝试将其写出来,但它告诉我以下错误。

TypeError: x[i].getElementsByTagName(ResourcesInfo)[0].childNodes[0] 未定义。

câu trả lời hay nhất

Here我已经为您修复了解析逻辑。

神奇的地方就在这里:

document.write("");

var x = xmlDoc.getElementsByTagName("ResourceGroup");

for (i = 0; i < x.length; i++) {
document.write("");
var y = x[i].getElementsByTagName("ResourcesInfo");
for (j = 0; j < y.length; j++) {
if (x[i].getAttribute("type") == "HUMANS") {
document.write("");
} khác {
document.write("");
}
}
document.write("");
}
document.write("
" + y[j].getAttribute('JobPosition') + "" +y[j].getAttribute('MachineName') + "
");
}

摆弄代码以解析和创建所需的 HTML 表格结构。

关于javascript - 使用 javascript 在 HTML 中显示 XML 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20944156/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress