XmlNodeReader.Skip Metoda

Definice

Přeskočí podřízené položky aktuálního uzlu.

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

Příklady

Následující příklad přečte uzel elementu price v dokumentu 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

Poznámky

Poznámka

V .NET Framework 2.0 doporučujeme vytvářet XmlReader instance pomocí XmlReaderSettings třídy a Create metody. Díky tomu můžete plně využívat všechny nové funkce zavedené v .NET Framework. Další informace najdete v části Poznámky na XmlReader referenční stránce.

Předpokládejme například, že máte následující vstup XML:

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

Pokud je čtečka umístěna na uzlu "<a>" nebo na některý z jeho atributů, zavolá Skip čtenáře na uzel "<b>".

Pokud je čtečka umístěna na listovém uzlu (například element "x" nebo textový uzel "abc"), volání Skip je stejné jako volání Read.

Tato metoda kontroluje správně formátovaný XML.

Platí pro