Atribut nodeType DOM XML
Definisi dan penggunaan
Atribut nodeType kembalikan tipe node.
Syarat:
attrObject.nodeType
contoh
Dalam semua contoh, kita akan menggunakan berkas XML books.xml,dan fungsi JavaScript loadXMLDoc()。
Kode potongan di bawah ini menunjukkan nama, nilai, dan tipe node atribut category:
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].nodeName);
document.write(" = ");
document.write(x.item(i).attributes[0].nodeValue);
document.write(" (nodetype: ");
document.write(x.item(i).attributes[0].nodeType
+ ")");
document.write("<br />");
}
Hasil kode di atas adalah:
category = children (nodetype: 2) category = cooking (nodetype: 2) category = web (nodetype: 2) category = web (nodetype: 2)