Allows random access to individual nodes within the collection.
var objXMLDOMNode = oXMLDOMNamedNodeMap.item(index);
An object. Returns IXMLDOMNode. Returns Null if the index is out of range.
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);
}
Set objXMLDOMNode = oXMLDOMNamedNodeMap.item(index)
An object. Returns IXMLDOMNode. Returns Null if the index is out of range.
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
HRESULT get_item( long index, IXMLDOMNode **listItem);
IXMLDOMNode object. Returns Null if the index is out of range.listItem parameter is Null.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.
Applies to: IXMLDOMNamedNodeMap | IXMLDOMSelection