attributes Property
Contains the list of attributes for this node.
Script Syntax
var objXMLDOMNamedNodeMap = oXMLDOMNode.attributes;
Example
The following creates an IXMLDOMNamedNodeMap
object from a document's attributes
property, and then displays the number of nodes in the object.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var oNamedNodeMap; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { oNamedNodeMap = xmlDoc.documentElement.firstChild.attributes; alert(oNamedNodeMap.length); }
Visual Basic Syntax
Set objXMLDOMNamedNodeMap = oXMLDOMNode.attributes
Example
The following creates an IXMLDOMNamedNodeMap
object from a document's attributes
property, and then displays the number of nodes in the object.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim oNamedNodeMap As IXMLDOMNamedNodeMap xmlDoc.async = False xmlDoc.Load ("books.xml") If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set oNamedNodeMap = xmlDoc.documentElement.firstChild.Attributes MsgBox oNamedNodeMap.length End If
C/C++ Syntax
HRESULT get_attributes( IXMLDOMNamedNodeMap **attributeMap);
Parameters
- attributeMap [out, retval]
- An
IXMLDOMNamedNodeMap
returned for nodes that can return attributes (Element
,Entity
, andNotation
nodes). Returns Null for all other node types. For the valid node types, theNamedNodeMap
is always returned; when there are no attributes on the element, the list length is set to zero.
C/C++ Return Values
- S_OK
- Success. Returns a nonnull pointer value.
- S_FALSE
- The value returned if the node type does not allow attributes.
- E_INVALIDARG
- The value returned if
attributeMap
is Null.
Remarks
The property is read-only. Returns IXMLDOMNamedNodeMap
for nodes that can return attributes (Element
, Entity
, and Notation
nodes). Returns Null for all other node types. For the valid node types, the NamedNodeMap
is always returned; when there are no attributes on the element, the list length is set to 0.
This value depends on the value of the nodeType
property.
NODE_ATTRIBUTE
NODE_CDATA_SECTION NODE_COMMENT NODE_DOCUMENT NODE_DOCUMENT_FRAGMENT NODE_ENTITY_REFERENCE NODE_TEXT |
Always returns Null. |
NODE_ELEMENT | Returns IXMLDOMNamedNodeMap that contains a list of nodes corresponding to the attributes of the element. |
NODE_PROCESSING_INSTRUCTION | Returns null for all processing instructions except the XML declaration, for example,<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>
For the XML declaration, the version, encoding, and standalone specifications can be accessed as attributes from the corresponding node. |
NODE_DOCUMENT_TYPE | Values specified in the <!DOCTYPE ...> can be accessed as attributes from the node corresponding to the document type declaration. The names are "SYSTEM" and "PUBLIC". They are uppercase. |
NODE_ENTITY
NODE_NOTATION |
Returns IXMLDOMNamedNodeMap that exposes the PUBLIC ID, SYSTEM ID, and NDATA as attributes. |
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
See Also
IXMLDOMNamedNodeMap | nodeType Property
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText