PROPERTY:  Attr::value

Attr.value

The value property returns the value for the attribute. This will either be the value specified in the XML file or, if there isn't one but the attribute has a default value assigned in a DTD, a default value. This property is returned as a string with character and general entity references being replaced with their values.

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 values.

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].value + "<br>");

Output:
123456
3



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