XML DOM nodeName attribute

Definition and Usage

Ang nodeName attribute ay ibabalik ang pangalan ng elemento ayon sa uri ng elemento.

Grammar:

attrObject.nodeName

Sample

Sa lahat ng mga halimbawa, gagamitin namin ang XML file books.xmlat ang JavaScript function loadXMLDoc()

ការបង្ហាញបន្ទាត់នេះ បង្ហាញអត្ថបទ 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 />");
}

លទ្ធផលនៃការបង្កើតនេះគឺ:

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