This property returns the name of the attribute, and is the same as the nodeName property for this Node object.
The name property is read-only and returns the name of the attribute. It is the same as the nodeName property for this Node object.
XML:
<staff>
<employee ssn="123456" pay="3">
<f_name>John</f_name>
<l_name>Sullivan</l_name>
</employee>
<employee ssn="987654" pay="2">
<f_name>Mary</f_name>
<l_name>Lopez</l_name>
</employee>
</staff>
JavaScript:
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("staff.xml");
employee = xml_doc.documentElement.firstChild;
atts = employee.attributes;
n_atts = atts.length;
for (i = 0; i < n_atts; i++)
document.write(atts[i].name + "<br>");
ssn
pay
This example uses the 'staff.xml' file and obtains a NamedNodeMap of all the attributes of the first child element of the document's root node. It then iterates through them displaying their names.