Compability: Internet Explorer
This property returns a boolean value which indicates whether or not this attribute has a value specified in the XML document.
If a value is specified in the document then it returns true. If no value is specified in the document, but the DTD for it specifies a default value, then specified returns false. Otherwise, if there is no value assigned in the XML document, and the value assigned to the attribute in the DTD is #IMPLIED, then the attribute does not appear in the structure model for the document.
XML:
<staff>
<employee ssn="123456" pay="3">
<f_name>John</f_name>
<l_name>Sullivan</l_name>
</employee>
<employee ssn="987654">
<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");
root = xml_doc.documentElement;
n_children = root.childNodes.length;
for (i = 0; i < n_children; i++)
{
curr_node = root.childNodes.item(i);
atts = curr_node.attributes;
document.write(atts[1].specified + "<br>");
}
true
false
This example example uses the 'staff.xml' file where the second 'employee' element does not have a 'pay' ttribute, but where a default value is specified in the DTD for the document. The code loops through the children of the root element and assigns the attributes of each to a NamedNodeMap. The specified property is then displayed for the 'pay' attribute.
Note:
The specified property will always return true for any node type other than an attribute.