İngilizce dilinde oku

Aracılığıyla paylaş


XmlNode.GetEnumerator Yöntem

Tanım

Geçerli düğümdeki alt düğümler arasında yineleyen bir numaralandırıcı alır.

C#
public System.Collections.IEnumerator GetEnumerator();

Döndürülenler

IEnumerator Geçerli düğümdeki alt düğümler arasında yineleme yapmak için kullanılabilecek bir nesne.

Örnekler

Aşağıdaki örnek, XML belgesindeki tüm kitapları görüntüler.

C#
using System;
using System.Collections;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlDocument doc = new XmlDocument();
    doc.Load("books.xml");

    Console.WriteLine("Display all the books...");
    XmlNode root = doc.DocumentElement;
    IEnumerator ienum = root.GetEnumerator();
    XmlNode book;
    while (ienum.MoveNext())
    {
      book = (XmlNode) ienum.Current;
      Console.WriteLine(book.OuterXml);
      Console.WriteLine();
    }
  }
}

Örnekte giriş books.xmlolarak dosyası kullanılır.

XML

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

Açıklamalar

içindeki düğümler üzerinde "her biri için" stil yinelemesi XmlNodeiçin destek sağlar.

Bu yöntem, Belge Nesne Modeli'nin (DOM) Microsoft bir uzantısıdır.

Şunlara uygulanır

Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0