XmlNodeReader.Skip メソッド

定義

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

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

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

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

注釈

Note

新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。

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

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

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

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

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

適用対象