XML DOM คุณสมบัติประเภทโหนด
❮ วัตถุโหนด
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books.xml " ลงใน xmlDoc และแสดงชื่อโหนดและประเภทโหนดของโหนดรูท:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
document.getElementById("demo").innerHTML =
"Nodename:
" + xmlDoc.nodeName +
" (nodetype: " + xmlDoc.nodeType
+ ")";
}
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Nodename: #document (nodetype: 9)
ความหมายและการใช้งาน
คุณสมบัติ nodeType ส่งคืนประเภทโหนดของโหนด
ไวยากรณ์
nodeObject.nodeType
❮ วัตถุโหนด