XmlNodeReader.Skip Método

Definição

Ignora os subordinados do nó atual.

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

Exemplos

O exemplo a seguir lê o nó do elemento price no documento XML.

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

Comentários

Note

Para aproveitar os recursos mais recentes, a prática recomendada é criar XmlReader instâncias usando a XmlReaderSettings classe e o Create método. Para obter mais informações, consulte a seção Comentários na XmlReader página de referência.

Por exemplo, suponha que você tenha a seguinte entrada XML:

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

Se o leitor estiver posicionado no nó "<a" ou em qualquer um> de seus atributos, chamar posicionará Skip o leitor para o nó "<b>".

Se o leitor já estiver posicionado em um nó folha (como o elemento "x" ou o nó de texto "abc"), a chamada Skip será a mesma que chamar Read.

Esse método verifica se há XML bem formado.

Aplica-se a