XMLドキュメントのルート要素の直下にある要素の数を表示するには、このhtml / javascriptファイルが必要です。
これは次のように表示されます。
The root element has this many direct children: 2
代わりに、次のように表示されます。
The root element has this many direct children: 0The root element has this many direct children: 1
どうすればこれを行うことができますか?
これは私が使用しているコードです:
<html land="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function loadXMLDoc(XML65) {
xhttp = new XMLHttpRequest();
xhttp.open("GET", XML65, false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<h1>Testing XML FILE</h1>
<script>
var xmlDoc = loadXMLDoc("XML65.xml");
for (i = 0; i < xmlDoc.childNodes.length; i++)
{
thisNode = xmlDoc.childNodes[i];
document.write("The root element has this many direct children: " + i);
}
</script>
</body>
</html>
スクリプトは次のようになります
var xmlDoc = loadXMLDoc("XML65.xml");
document.write("The root element has this many direct children: " + xmlDoc.childNodes.length);
PS私はに代わるものに精通することを強くお勧めします document.write
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加