length Property (IXMLDOMNamedNodeMap)

 

Indicates the number of items in the collection.

Script Syntax

lValue = oXMLDOMNamedNodeMap.length;  

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
var nodeBook, namedNodeMap;
xmlDoc.setProperty("SelectionLanguage", "XPath");
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   nodeBook = xmlDoc.selectSingleNode("//book");
   namedNodeMap = nodeBook.attributes;
   WScript.Echo(namedNodeMap.length);
}

Visual Basic Syntax

lValue = oXMLDOMNamedNodeMap.length  

C/C++ Syntax

HRESULT get_length(  
    long *listLength);  

Parameters

listLength[out, retval]
The number of items in the collection.

C/C++ Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the listLength is Null.

Example

IXMLDOMNode *pIXMLDOMNode = NULL;
IXMLDOMNamedNodeMap *pIXMLDOMNamedNodeMap = NULL;
IXMLDOMElement *pIXMLDOMElement = NULL;
long lLength;
TCHAR strTemp[10];
HRESULT hr;
IXMLDOMDocument *pIXMLDOMDocument = NULL;

try
{
  // Create an instance of DOMDocument and initialize pIXMLDOMDocument.
  // Load/create an XML fragment.
  hr = pIXMLDOMDocument->get_documentElement(&pIXMLDOMElement);
  SUCCEEDED(hr) ? 0 : throw hr;

  if(pIXMLDOMElement)
  {
    hr = pIXMLDOMElement->get_attributes(&pIXMLDOMNamedNodeMap);
    if(SUCCEEDED(hr) && pIXMLDOMNamedNodeMap)
    {
      hr = pIXMLDOMNamedNodeMap->get_length(&lLength);
      if(SUCCEEDED(hr))
      {
        _itot(lLength, strTemp, 10);
        ::MessageBox(NULL, strTemp, _T("Number of Attributes"), MB_OK);
      }
      pIXMLDOMNamedNodeMap->Release();
      pIXMLDOMNamedNodeMap = NULL;
    }
    pIXMLDOMElement->Release();
    pIXMLDOMElement = NULL;
  }
}
catch(...)
{
  if(pIXMLDOMElement)
    pIXMLDOMElement->Release();
  if(pIXMLDOMNamedNodeMap)
    pIXMLDOMNamedNodeMap->Release();
  DisplayErrorToUser();
}
// Release pIXMLDOMDocument when finished with it.

Remarks

Long integer. The property is read-only.

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

Applies to

IXMLDOMNamedNodeMap