XmlNodeReader.Skip メソッド

定義

現在のノードの子をスキップします。

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

次の例では、XML ドキュメント内の price 要素ノードを読み取ります。

#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

注釈

注意

.NET Framework 2.0 では、クラスとCreateメソッドを使用してインスタンスをXmlReaderSettings作成XmlReaderすることをお勧めします。 これにより、.NET Frameworkで導入されたすべての新機能を最大限に活用できます。 詳細については、リファレンス ページの「解説」セクションを XmlReader 参照してください。

たとえば、次の XML 入力があるとします。

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

リーダーが "<a>" ノードまたはその属性のいずれかに配置されている場合、呼び出しは Skip リーダーを "<b>" ノードに配置します。

リーダーが既にリーフ ノード (要素 "x" やテキスト ノード "abc" など) に配置されている場合、呼び出しは呼び出しSkipReadと同じです。

このメソッドは、整形式の XML をチェックします。

適用対象