XmlNodeList::Count Property


Gets the number of nodes in the XmlNodeList.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

property int Count {
	virtual int get() abstract;

Property Value

Type: System::Int32

The number of nodes in the XmlNodeList.

The following example creates a XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList to display all the book titles.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "2books.xml" );

   // Get and display all the book titles.
   XmlElement^ root = doc->DocumentElement;
   XmlNodeList^ elemList = root->GetElementsByTagName( "title" );
   for ( int i = 0; i < elemList->Count; i++ )
      Console::WriteLine( elemList[ i ]->InnerXml );

The example uses the file 2books.xml as input.

<!--sample XML fragment-->
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top