This documentation is archived and is not being maintained.

XmlNamedNodeMap.GetEnumerator Method

Provides support for the "foreach" style iteration over the collection of nodes in the XmlNamedNodeMap.

[Visual Basic]
Public Overridable Function GetEnumerator() As IEnumerator _
   Implements IEnumerable.GetEnumerator
public virtual IEnumerator GetEnumerator();
public: virtual IEnumerator* GetEnumerator();
public function GetEnumerator() : IEnumerator;

Return Value

An IEnumerator.




[Visual Basic, C#, C++] The following example displays all attributes in the collection.

[Visual Basic] 
Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml
Imports System.Collections

public class Sample
  public shared sub Main()

      Dim doc as XmlDocument = new XmlDocument()
      doc.LoadXml("<book genre='novel' publicationdate='1997' " & _
                  "      ISBN='1-861001-57-5'>" & _
                  "  <title>Pride And Prejudice</title>" & _

      Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes

      Console.WriteLine("Display all the attributes for this book...")
      Dim ienum as IEnumerator = attrColl.GetEnumerator()
      Dim attr as XmlAttribute   
      while (ienum.MoveNext())
        attr = CType(ienum.Current, XmlAttribute)
        Console.WriteLine("{0} = {1}", attr.Name, attr.Value)
      end while 

  end sub
end class

using System;
using System.IO;
using System.Xml;
using System.Collections;

public class Sample
  public static void Main()

      XmlDocument doc = new XmlDocument();
      doc.LoadXml("<book genre='novel' publicationdate='1997' " +
                  "      ISBN='1-861001-57-5'>" +
                  "  <title>Pride And Prejudice</title>" +

      XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

      Console.WriteLine("Display all the attributes for this book...");
      IEnumerator ienum = attrColl.GetEnumerator();
      while (ienum.MoveNext())
        XmlAttribute attr = (XmlAttribute)ienum.Current;
        Console.WriteLine("{0} = {1}", attr.Name, attr.Value);

#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
 using namespace System::IO;
 using namespace System::Xml;
 using namespace System::Collections;
int main()
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<book genre='novel' publicationdate='1997' " 
                 S"      ISBN='1-861001-57-5'>" 
                 S"  <title>Pride And Prejudice</title>" 
    XmlAttributeCollection* attrColl = doc->DocumentElement->Attributes;

    Console::WriteLine(S"Display all the attributes for this book...");
    IEnumerator* ienum = attrColl->GetEnumerator();
    while (ienum->MoveNext())
        XmlAttribute* attr = dynamic_cast<XmlAttribute*>(ienum->Current);
        Console::WriteLine(S"{0} = {1}", attr->Name, attr->Value);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlNamedNodeMap Class | XmlNamedNodeMap Members | System.Xml Namespace