次の方法で共有


XmlNodeReader.Skip メソッド

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

Overrides Public Sub Skip()
[C#]
public override void Skip();
[C++]
public: void Skip();
[JScript]
public override function Skip();

解説

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

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

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

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

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

使用例

[Visual Basic, C#, C++] XML ドキュメントの価格要素ノードを読み取る例を次に示します。

 
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

[C#] 
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

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlNodeReader* reader = 0;

   try
   {
      //Create and load the XML document.
      XmlDocument* doc = new XmlDocument();
      doc->LoadXml(S"<!-- sample XML -->" 
                   S"<book>" 
                   S"<title>Pride And Prejudice</title>" 
                   S"<price>19.95</price>" 
                   S"</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 != 0)
         reader->Close();
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

XmlNodeReader クラス | XmlNodeReader メンバ | System.Xml 名前空間