XmlTextReader.GetRemainder メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlTextReader.GetRemainder メソッドの意味・解説 

XmlTextReader.GetRemainder メソッド

バッファ内の XML剰余取得します

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Function GetRemainder As
 TextReader
Dim instance As XmlTextReader
Dim returnValue As TextReader

returnValue = instance.GetRemainder
public TextReader GetRemainder ()
public:
TextReader^ GetRemainder ()
public TextReader GetRemainder ()
public function GetRemainder () : TextReader

戻り値
バッファ内の XML剰余格納している TextReader。

解説解説

XmlTextReader はバッファ内の読み取り実行するため、データ消失しないように、未使用バッファ剰余返すことができる必要があります。これにより、プロトコル (マルチパート MIME など) で XML を他のものと同じストリームパッケージ化できます

このメソッド呼び出すと、EOFtrue設定されます。

使用例使用例

XML ドキュメント最初部分読み取り次に GetRemainder使用して2 番目のリーダー使用したドキュメント読み取り完了する例を次に示します

Imports System
Imports System.Xml

Public Class Sample
    Private Shared filename As
 String = "tworeads.xml"
    
    Public Shared Sub Main()

        Dim reader As New
 XmlTextReader(filename)
        reader.WhitespaceHandling = WhitespaceHandling.None
        
        ' Read the first part of the XML document
        While reader.Read()
            ' Display the elements and stop reading on the book endelement
 tag
            ' then go to ReadPart2 to start another reader to read the
 rest of the file. 
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    Console.WriteLine("Name: {0}",
 reader.Name)
                Case XmlNodeType.Text
                    Console.WriteLine("  Element Text: {0}",
 reader.Value)
                Case XmlNodeType.EndElement
                    ' Stop reading when the reader gets to the end element
 of the book node.
                    If "book" =
 reader.LocalName Then
                        Console.WriteLine("End reading first book...")
                        Console.WriteLine()
                        GoTo ReadPart2
                    End If
            End Select
        End While
        
        ' Read the rest of the XML document
        ReadPart2: 
        Console.WriteLine("Begin reading second book...")
        
        ' Create a new reader to read the rest of the document.
        Dim reader2 As New
 XmlTextReader(reader.GetRemainder())
        
        While reader2.Read()
            Select Case reader2.NodeType
                Case XmlNodeType.Element
                    Console.WriteLine("Name: {0}",
 reader2.Name)
                Case XmlNodeType.Text
                    Console.WriteLine("  Element Text: {0}",
 reader2.Value)
                Case XmlNodeType.EndElement
                    'Stop reading when the reader gets to the end element
 of the book node.
                    If "book" =
 reader2.LocalName Then
                        Console.WriteLine("End reading second
 book...")
                        GoTo Done
                    End If
            End Select
        End While
        
        Done: 
        Console.WriteLine("Done.")
        reader.Close()
        reader2.Close()
    End Sub 'Main
End Class 'Sample
using System;
using System.Xml; 

public class Sample {

  private static string
 filename = "tworeads.xml";
   
  public static void Main()
 {
  
    XmlTextReader reader = new XmlTextReader(filename);
    reader.WhitespaceHandling=WhitespaceHandling.None;

    // Read the first part of the XML document
    while(reader.Read()) {
      // Display the elements and stop reading on the book endelement
 tag
      // then go to ReadPart2 to start another reader to read the rest
 of the file. 
      switch(reader.NodeType) {
       case XmlNodeType.Element:
        Console.WriteLine("Name: {0}", reader.Name);
        break;
       case XmlNodeType.Text:
        Console.WriteLine("  Element Text: {0}", reader.Value);
        break;
       case XmlNodeType.EndElement:
        // Stop reading when the reader gets to the end element of the
 book node.
        if ("book"==reader.LocalName) {
          Console.WriteLine("End reading first book...");
          Console.WriteLine();      
          goto ReadPart2;
        }
        break;
      } 
    } 

    // Read the rest of the XML document
    ReadPart2:
    Console.WriteLine("Begin reading second book...");

    // Create a new reader to read the rest of the document.
    XmlTextReader reader2 = new XmlTextReader(reader.GetRemainder());

    while(reader2.Read()) {
      switch (reader2.NodeType) {
        case XmlNodeType.Element:
         Console.WriteLine("Name: {0}", reader2.Name);
         break;
        case XmlNodeType.Text:
         Console.WriteLine("  Element Text: {0}", reader2.Value);
         break;
        case XmlNodeType.EndElement:
         // Stop reading when the reader gets to the end element of the
 book node.
         if ("book"==reader2.LocalName) {
           Console.WriteLine("End reading second book...");
           goto Done;
         }
         break;
      }
    }

    Done:
    Console.WriteLine("Done.");
    reader.Close(); 
    reader2.Close();
  }
}//End class
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   String^ filename = "tworeads.xml";
   XmlTextReader^ reader = gcnew XmlTextReader( filename );
   reader->WhitespaceHandling = WhitespaceHandling::None;
   
   // Read the first part of the XML document
   while ( reader->Read() )
   {
      
      // Display the elements and stop reading on the book endelement
 tag
      // then go to ReadPart2 to start another reader to read the rest
 of the file. 
      switch ( reader->NodeType )
      {
         case XmlNodeType::Element:
            Console::WriteLine( "Name: {0}", reader->Name );
            break;

         case XmlNodeType::Text:
            Console::WriteLine( "  Element Text: {0}", reader->Value
 );
            break;

         case XmlNodeType::EndElement:
            
            // Stop reading when the reader gets to the end element of the
 book node.
            if ( "book" == reader->LocalName )
            {
               Console::WriteLine( "End reading first book..." );
               Console::WriteLine();
               goto ReadPart2;
            }
            break;
      }
   }

   
   // Read the rest of the XML document
   
ReadPart2:
   Console::WriteLine( "Begin reading second book..." );
   
   // Create a new reader to read the rest of the document.
   XmlTextReader^ reader2 = gcnew XmlTextReader( reader->GetRemainder() );
   while ( reader2->Read() )
   {
      switch ( reader2->NodeType )
      {
         case XmlNodeType::Element:
            Console::WriteLine( "Name: {0}", reader2->Name );
            break;

         case XmlNodeType::Text:
            Console::WriteLine( "  Element Text: {0}", reader2->Value
 );
            break;

         case XmlNodeType::EndElement:
            
            // Stop reading when the reader gets to the end element of the
 book node.
            if ( "book" == reader2->LocalName )
            {
               Console::WriteLine( "End reading second book..." );
               goto Done;
            }
            break;
      }
   }

   
Done:
   Console::WriteLine( "Done." );
   reader->Close();
   reader2->Close();
}

import System.*;
import System.Xml.*;

public class Sample
{
    private static String fileName = "tworeads.xml";

    public static void main(String[]
 args)
    {
        XmlTextReader reader = new XmlTextReader(fileName);
        reader.set_WhitespaceHandling(WhitespaceHandling.None);

        // Read the first part of the XML document
        while (reader.Read()) {

            // Display the elements and stop reading on the book endelement
 tag
            // then go to ReadPart2 to start another reader to read
 the rest
            // of the file. 
            switch (reader.get_NodeType()) {
                case XmlNodeType.Element :
                    Console.WriteLine("Name: {0}", reader.get_Name());
                    break;
                case XmlNodeType.Text :
                    Console.WriteLine("  Element Text: {0}", reader.get_Value());
                    break;
                case XmlNodeType.EndElement :

                    // Stop reading when the reader gets to the end
 element 
                    //of the book node.
                    if ("book".Equals(reader.get_LocalName()))
 {
                        Console.WriteLine("End reading first book...");
                        Console.WriteLine();
                    }
                    break;
            }
        }

        // Read the rest of the XML document
        // Create a new reader to read the rest of the document.
        XmlTextReader reader2 = new XmlTextReader(reader.GetRemainder());
        while (reader2.Read()) {
            switch (reader2.get_NodeType()) {
                case XmlNodeType.Element :
                    Console.WriteLine("Name: {0}", reader2.get_Name());
                    break;
                case XmlNodeType.Text :
                    Console.WriteLine
                        ("  Element Text: {0}", reader2.get_Value());
                    break;
                case XmlNodeType.EndElement :
                    // Stop reading when the reader gets to the end
 element
                    // of the book node.
                    if ("book".Equals(reader2.get_LocalName()))
 {
                        Console.WriteLine("End reading second book...");
                    }
                    break;
            }
        }
        reader.Close();
        reader2.Close();
    } //main
}//End class Sample

この例では、tworeads.xml という入力ファイル使用してます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlTextReader.GetRemainder メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlTextReader.GetRemainder メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS