PROPERTY:  Attr::name

Attr.name

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.

The following 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.

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>

Code (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>");

Output:
ssn
pay



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information