item Method (IXMLDOMNamedNodeMap)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

item Method (IXMLDOMNamedNodeMap)

Allows random access to individual nodes within the collection.

[Script]

Script Syntax

var objXMLDOMNode = oXMLDOMNamedNodeMap.item(index);

Parameters

index
A long integer. An index of the item within the collection. The first item is zero.

Return Value

An object. Returns IXMLDOMNode. Returns Null if the index is out of range.

Example

The following script example creates an IXMLDOMNamedNodeMap object to retrieve the attributes for an element node selected using the SelectSingleNode method. It then iterates through the attributes, before displaying the name and value of each attribute in the collection.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var oNamedNodeMap, nodeBook, str;
var str = "";
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   xmlDoc.setProperty("SelectionLanguage", "XPath");
   nodeBook = xmlDoc.selectSingleNode("//book");
   oNamedNodeMap = nodeBook.attributes;
   for (var i=0; i<oNamedNodeMap.length; i++) {
      str += "Attr" + i + " name: " + 
         oNamedNodeMap.item(i).name + "\n" +
         "Attr" + i + " value: " + 
         oNamedNodeMap.item(i).text + "\n";
   }
   alert(str);
}
[Visual Basic]

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMNamedNodeMap.item(index)

Parameters

index
A long integer. Index of the item within the collection. The first item is zero.

Return Value

An object. Returns IXMLDOMNode. Returns Null if the index is out of range.

Example

The following Microsoft® Visual Basic® example creates an IXMLDOMNamedNodeMap object to retrieve the attributes for an element node selected using the SelectSingleNode method. It then iterates through the attributes, before displaying the name and value of each attribute in the collection.

Dim xmlDoc As New MSXML2.DOMDocument50
Dim oNamedNodeMap As IXMLDOMNamedNodeMap
Dim nodeBook As IXMLDOMElement
Dim str As String
str = ""
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 nodeBook = xmlDoc.selectSingleNode("//book")
   Set oNamedNodeMap = nodeBook.Attributes
   For i = 0 To (oNamedNodeMap.length - 1)
      str = str & _
         "Attr" & CStr(i) & " name: " & _
         oNamedNodeMap.Item(i).nodeName & vbCrLf & _
         "Attr" & CStr(i) & " value: " & _
         oNamedNodeMap.Item(i).nodeValue & vbCrLf
   Next
   MsgBox str
End If
[C/C++]

C/C++ Syntax

HRESULT get_item(
  long index,
  IXMLDOMNode **listItem);

Parameters

index [in]
The index of the item within the collection. The first item is zero.
listItem [out, retval]
The IXMLDOMNode object. Returns Null if the index is out of range.

C/C++ Return Values

S_OK
The value returned if successful.
E_INVALIDARG
The value returned if the listItem parameter is Null.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IXMLDOMNode

Applies to: IXMLDOMNamedNodeMap | IXMLDOMSelection