XML DOM nodeType shuxing

dingyi he yongfa

nodeType shuxing hui fan zhujie de leixing.

yufa:

attrObject.nodeType

shili

zai suoyou de li例 zhong, women jiang shi yong XML wenjian books.xmldanji, jieyu JavaScript hanyu loadXMLDoc()

Kode potongan di bawah ini menunjukkan nama node, nilai node serta 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 />");
}

Output kode di atas:

category = children (nodetype: 2)
category = cooking (nodetype: 2)
category = web (nodetype: 2)
category = web (nodetype: 2)