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

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

XmlValidatingReader.ReadString メソッド

要素ノードまたはテキスト ノード内容文字列として読み取ります。

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

解説解説

要素配置すると、ReadString は、すべてのテキスト有意な空白空白、および CDATA セクション ノード型を連結し連結したデータ要素内容として返しますリーダーは、任意のマークアップ見つかった時点停止しますコメント処理命令マークアップと見なされます。これは、混合コンテンツ モデル内で、または要素終了タグ読み取られるときに、発生する可能性あります

テキスト ノード配置されると、ReadString は、テキスト ノードから要素終了タグへの連結実行しますリーダー属性テキスト ノード配置されている場合ReadString は、リーダー要素開始タグ配置されている場合と同じ機能持ちます連結され要素テキスト ノードをすべて返します

EntityHandling は、ReadStringどのように機能するかを次のように決定します

使用例使用例

各要素テキストの内容表示する例を次に示します

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
   
   Public Shared Sub Main()
      Dim txtreader As XmlTextReader = Nothing
      Dim reader As XmlValidatingReader = Nothing
      
      Try
         'Implement the readers.
         txtreader = New XmlTextReader("elems.xml")
         reader = New XmlValidatingReader(txtreader)
         
         'Parse the XML and display the text content of each of the
 elements.
         While reader.Read()
            If reader.IsStartElement() Then
               If reader.IsEmptyElement Then
                  Console.WriteLine("<{0}/>",
 reader.Name)
               Else
                  Console.Write("<{0}> ", reader.Name)
                  reader.Read() 'Read the start tag.
                  If (reader.IsStartElement())  'Handle
 nested elements.
                    Console.WriteLine()
                    Console.Write("<{0}>", reader.Name)
                  End If
                  Console.WriteLine(reader.ReadString()) 'Read the text
 content of the element.
               End If
            End If
         End While      
      
      Finally
         If Not (reader Is
 Nothing) Then
            reader.Close()
         End If
      End Try
   End Sub 'Main 
End Class 'Sample
using System;
using System.IO;
using System.Xml;

public class Sample 
{
  public static void Main()
  {
    XmlTextReader txtreader = null;
    XmlValidatingReader reader = null;

    try
    {
       //Implement the readers.
       txtreader = new XmlTextReader("elems.xml");
       reader = new XmlValidatingReader(txtreader);
  
       //Parse the XML and display the text content of each of the elements.
       while (reader.Read()){
         if (reader.IsStartElement()){
           if (reader.IsEmptyElement)
              Console.WriteLine("<{0}/>", reader.Name);
           else{
               Console.Write("<{0}> ", reader.Name);
               reader.Read(); //Read the start tag.
               if (reader.IsStartElement())  //Handle
 nested elements.
                   Console.Write("\r\n<{0}>", reader.Name);
               Console.WriteLine(reader.ReadString());  //Read the text
 content of the element.
           }
         }
       } 
       
     } 

     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
  
} // End class
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ txtreader = nullptr;
   XmlValidatingReader^ reader = nullptr;
   try
   {
      
      //Implement the readers.
      txtreader = gcnew XmlTextReader( "elems.xml" );
      reader = gcnew XmlValidatingReader( txtreader );
      
      //Parse the XML and display the text content of each of the elements.
      while ( reader->Read() )
      {
         if ( reader->IsStartElement() )
         {
            if ( reader->IsEmptyElement )
                        Console::WriteLine( "<{0}/>", reader->Name
 );
            else
            {
               Console::Write( "<{0}> ", reader->Name );
               reader->Read(); //Read the start tag.
               if ( reader->IsStartElement() )
                              
               //Handle nested elements.
               Console::Write( "\r\n<{0}>", reader->Name );
               Console::WriteLine( reader->ReadString() ); //Read
 the text content of the element.
            }
         }
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}

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

public class Sample
{
    public static void main(String[]
 args)
    {
        XmlTextReader txtReader = null;
        XmlValidatingReader reader = null;

        try {
            //Implement the readers.
            txtReader = new XmlTextReader("elems.xml");
            reader = new XmlValidatingReader(txtReader);

            //Parse the XML and display the text content of
            // each of the elements.
            while (reader.Read()) {
                if (reader.IsStartElement()) {
                    if (reader.get_IsEmptyElement()) {
                        Console.WriteLine("<{0}/>", reader.get_Name());
                    }
                    else {
                        Console.Write("<{0}> ", reader.get_Name());
                        reader.Read(); //Read the start tag.
                        if (reader.IsStartElement()) {
                         //Handle nested elements.
                            Console.Write("\r\n<{0}>", reader.get_Name());
                        }
                        Console.WriteLine(reader.ReadString()); 
                        //Read the text content of the element.
                    }
                }
            }
        }
        finally {
            if (reader != null) {
                reader.Close();
            }
      }
    } //main
} // End class Sample

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

<book>
  <title>Pride And
 Prejudice</title>
  <price>19.95</price>
  <misc/>
</book>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlValidatingReader.ReadString メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlValidatingReader.ReadString メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlValidatingReader.ReadString メソッド を検索

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS