Freigeben über


XmlNodeReader.Skip-Methode

Überspringt die untergeordneten Elemente des aktuellen Knotens.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Overrides Sub Skip
'Usage
Dim instance As XmlNodeReader

instance.Skip
public override void Skip ()
public:
virtual void Skip () override
public void Skip ()
public override function Skip ()

Hinweise

Hinweis

Die empfohlene Vorgehensweise für Microsoft .NET Framework, Version 2.0 besteht darin, XmlReader-Instanzen mithilfe der XmlReaderSettings-Klasse und der Create-Methode zu erstellen. Dies erlaubt es, alle Vorteile der neu in .NET Framework enthaltenen Features zu nutzen. Weitere Informationen finden Sie unter Erstellen von XML-Readern.

Nehmen Sie z. B. an, dass folgende XML-Eingabe vorliegt:

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

Wenn der Reader auf dem Knoten "<a>" oder einem von dessen Attributen positioniert ist, wird der Reader beim Aufruf von Skip auf dem Knoten "<b>" positioniert.

Wenn der Reader bereits auf einem Endknoten (z. B. auf Element "x" oder dem Textknoten "abc") positioniert ist, sind der Aufruf von Skip und der Aufruf von Read äquivalent.

Diese Methode prüft auf wohlgeformtes XML.

Beispiel

Im folgenden Beispiel wird der Preiselementknoten im XML-Dokument gelesen.

Option Explicit
Option Strict

Imports System
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 'Main
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
#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();
   }

}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        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();
            }
        }
    } //main
} //End class Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlNodeReader-Klasse
XmlNodeReader-Member
System.Xml-Namespace

Weitere Ressourcen

Lesen von XML mit dem "XmlReader"