Share via


XmlNodeReader.Skip 메서드

정의

현재 노드의 자식을 건너뜁니다.

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

예제

다음 예제에서는 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

설명

참고

.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")가 이미 리프 노드에 배치된 경우 호출 Skip 은 호출 Read과 동일합니다.

이 메서드는 올바른 형식의 XML을 확인합니다.

적용 대상