XmlNodeReader.Skip Yöntem

Tanım

Geçerli düğümün alt öğelerini atlar.

public:
 override void Skip();
public override void Skip();
override this.Skip : unit -> unit
Public Overrides Sub Skip ()

Örnekler

Aşağıdaki örnek, XML belgesindeki fiyat öğesi düğümünü okur.

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

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<!-- sample XML -->" +
                   "<book>" +
                   "<title>Pride And Prejudice</title>" +
                   "<price>19.95</price>" +
                   "</book>");

       //Load the XmlNodeReader
       reader = new XmlNodeReader(doc);

       reader.MoveToContent(); //Move to the book node.
       reader.Read();  //Read the book start tag.
       reader.Skip();   //Skip the title element.

       Console.WriteLine(reader.ReadOuterXml());  //Read the price element.
     }

     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load the XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<!-- sample XML -->" & _
                       "<book>" & _
                       "<title>Pride And Prejudice</title>" & _
                       "<price>19.95</price>" & _
                       "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            reader.MoveToContent() 'Move to the book node.
            reader.Read() 'Read the book start tag.
            reader.Skip() 'Skip the title element.
            Console.WriteLine(reader.ReadOuterXml()) 'Read the price element.
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Açıklamalar

Note

Daha yeni özelliklerden yararlanmak için önerilen yöntem, sınıfını ve yöntemini kullanarak XmlReader örnekler oluşturmaktır.XmlReaderSettingsCreate Daha fazla bilgi için başvuru sayfasındaki Açıklamalar bölümüne XmlReader bakın.

Örneğin, aşağıdaki XML girişlerine sahip olduğunuzu varsayalım:

<a name="bob" age="123">
   <x/>abc<y/>
 </a>
 <b>
...
 </b>

Okuyucu "<a>" düğümünde veya özniteliklerinden herhangi birinde konumlandırıldıysa, çağrısı Skip okuyucuyu "<b>" düğümüne yerleştirir.

Okuyucu zaten bir yaprak düğümde konumlandırılmışsa ("x" öğesi veya "abc" metin düğümü gibi), çağrısı Skip ile Readaynıdır.

Bu yöntem iyi biçimlendirilmiş XML'i denetler.

Şunlara uygulanır