XmlNodeReader.Skip Método

Definição

Ignora os filhos 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.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load the XML document.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<!-- sample XML -->"
      "<book>"
      "<title>Pride And Prejudice</title>"
      "<price>19.95</price>"
      "</book>" );
      
      //Load the XmlNodeReader 
      reader = gcnew 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 != nullptr )
            reader->Close();
   }

}
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

Observação

No .NET Framework 2.0, a prática recomendada é criar XmlReader instâncias usando a XmlReaderSettings classe e o Create método. Isso permite que você aproveite ao máximo todos os novos recursos introduzidos no .NET Framework. 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á 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"), chamar Skip será o mesmo que chamar Read.

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

Aplica-se a