item Method (IXMLDOMNodeList)
Allows random access to individual nodes within the collection.
JScript Syntax
var objXMLDOMNode = oXMLDOMNodeList.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 IXMLDOMNodeList
object with the document's getElementsByTagName
method. It then iterates through the collection, displaying the text value of each item in the list.
Note
You can use books.xml to run this sample code.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
var objNodeList;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
WScript.Echo("You have error " + myErr.reason);
} else {
objNodeList = xmlDoc.getElementsByTagName("author");
for (var i=0; i<objNodeList.length; i++) {
WScript.Echo(objNodeList.item(i).text);
}
}
Output
Gambardella, Matthew
Ralls, Kim
Corets, Eva
...
C/C++ Syntax
HRESULT get_item(
long index,
IXMLDOMNode **listItem);
Parameters
index
[in]
An index of the item within the collection. The first item is number zero.
listItem
[out, retval]
An IXMLDOMNode
. Returns Null if the index is out of range.
Return Values
S_OK
The value returned if successful.
E_INVALIDARG
The value returned if the listItem
parameter is Null.
Versioning
Implemented in: MSXML 3.0 and MSXML 6.0