XmlReader.ReadElementString メソッド ()とは? わかりやすく解説

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

XmlReader.ReadElementString メソッド ()

テキストだけの要素読み取ります。

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

Public Overridable Function
 ReadElementString As String
public virtual string ReadElementString ()
public:
virtual String^ ReadElementString ()
public String ReadElementString ()
public function ReadElementString () : String

戻り値
読み取られ要素内に格納されているテキスト要素が空 (<item></item> または <item/>) の場合は、空の文字列

例外例外
解説解説

これは、単純なテキストだけの要素読み取るためのヘルパー メソッドです。MoveToContent を呼び出して次のコンテンツ ノード検索してから、その値を単純文字列として解析します

XML<name>Arlene Huff</name>ReadElementString使用すると、要素処理され文字列 Arlene Huff返されます。

このメソッドname 要素内のマークアップ (子要素コメント処理命令など) を処理できませんが、複数隣接したテキスト ブロックと CDATA ブロック連結できます

このメソッド呼び出すと、EndElement ノード次のノードまたは空の要素タグ後ろリーダー配置されます。

使用例使用例

ReadElementString使用して要素ノード内容読み取る例を次に示します

Imports System
Imports System.Xml

public class Sample

  private const filename as
 string = "book.xml"

  public shared Sub Main()

    Dim reader as XmlTextReader = Nothing

    try
       
      ' Load the file and ignore all white space.
      reader = new XmlTextReader(filename)
      reader.WhitespaceHandling = WhitespaceHandling.None

      ' Moves the reader to the root element.
      reader.MoveToContent()

      ' Read the title and price elements.
      Console.WriteLine("Content of the title element: {0}",
 reader.ReadElementString())
      Console.WriteLine("Content of the price element: {0}",
 reader.ReadElementString())

    finally
      if Not reader Is Nothing
        reader.Close()
      End if
    End try

  End Sub
End class
using System;
using System.Xml;

public class Sample
{
  private const String filename = "book.xml";

  public static void Main()
  {
    XmlTextReader reader = null;

    try
    {           
      // Load the file and ignore all white space.
      reader = new XmlTextReader(filename);
      reader.WhitespaceHandling = WhitespaceHandling.None;

      // Moves the reader to the root element.
      reader.MoveToContent();

      // Read the title and price elements.
      Console.WriteLine("Content of the title element: {0}", reader.ReadElementString());
      Console.WriteLine("Content of the price element: {0}", reader.ReadElementString());;
 
         
    }
    finally
    {
      if (reader!=null)
        reader.Close();
    }
  }
} // End class
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   String^ filename = "book.xml";
   XmlTextReader^ reader = nullptr;
   try
   {
      
      // Load the file and ignore all white space.
      reader = gcnew XmlTextReader( filename );
      reader->WhitespaceHandling = WhitespaceHandling::None;
      
      // Moves the reader to the root element.
      reader->MoveToContent();
      
      // Read the title and price elements.
      Console::WriteLine( "Content of the title element: {0}", reader->ReadElementString()
 );
      Console::WriteLine( "Content of the price element: {0}", reader->ReadElementString()
 );
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}

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

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

    public static void main(String[]
 args)
    {
        XmlTextReader reader = null;
        try {
            // Load the file and ignore all white space.
            reader = new XmlTextReader(fileName);
            reader.set_WhitespaceHandling(WhitespaceHandling.None);

            // Moves the reader to the root element.
            reader.MoveToContent();

            // Read the title and price elements.
            Console.WriteLine("Content of the title element: {0}",
                reader.ReadElementString());
            Console.WriteLine("Content of the price element: {0}", 
                reader.ReadElementString());
        } 
        finally {
            if (reader != null) {
                reader.Close();
            }
        }
    } // main
} // End class Sample

この例では、データ ファイル book.xml使用してます。

<!--sample XML fragment-->
<book genre='novel' ISBN='1-861003-78'
 misc='sale-item'>
  <title>The Handmaid's
 Tale</title>
  <price>14.95</price>
</book>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlReader.ReadElementString メソッド (String, String)

テキストだけの要素読み取る前に見つかった要素の LocalName プロパティと NamespaceURI プロパティが、指定した文字列一致することを確認します

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

Public Overridable Function
 ReadElementString ( _
    localname As String, _
    ns As String _
) As String
Dim instance As XmlReader
Dim localname As String
Dim ns As String
Dim returnValue As String

returnValue = instance.ReadElementString(localname, ns)
public virtual string ReadElementString (
    string localname,
    string ns
)
public:
virtual String^ ReadElementString (
    String^ localname, 
    String^ ns
)
public String ReadElementString (
    String localname, 
    String ns
)
public function ReadElementString (
    localname : String, 
    ns : String
) : String

パラメータ

localname

確認対象ローカル名。

ns

確認対象名前空間 URI

戻り値
読み取られ要素内に格納されているテキスト要素が空 (<item></item> または <item/>) の場合は、空の文字列

例外例外
解説解説

これは、単純なテキストだけの要素読み取るためのヘルパー メソッドです。MoveToContent を呼び出して次のコンテンツ ノード検索してから、その値を単純文字列として解析します

XML<name>Arlene Huff</name>ReadElementString使用すると、要素処理され文字列 Arlene Huff返されます。

このメソッドname 要素内のマークアップ (子要素コメント処理命令など) を処理できませんが、複数隣接したテキスト ブロックと CDATA ブロック連結できます

このメソッド呼び出すと、EndElement ノード次のノードまたは空の要素タグ後ろリーダー配置されます。

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

XmlReader.ReadElementString メソッド (String)

テキストだけの要素読み取る前に見つかった要素Name プロパティが、指定した文字列一致することを確認します

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

Public Overridable Function
 ReadElementString ( _
    name As String _
) As String
public virtual string ReadElementString (
    string name
)
public:
virtual String^ ReadElementString (
    String^ name
)
public String ReadElementString (
    String name
)
public function ReadElementString (
    name : String
) : String

パラメータ

name

確認対象の名前。

戻り値
読み取られ要素内に格納されているテキスト要素が空 (<item></item> または <item/>) の場合は、空の文字列

例外例外
解説解説

これは、単純なテキストだけの要素読み取るためのヘルパー メソッドです。MoveToContent を呼び出して次のコンテンツ ノード検索してから、その値を単純文字列として解析します

XML<name>Arlene Huff</name>ReadElementString使用すると、要素処理され文字列 Arlene Huff返されます。

このメソッドname 要素内のマークアップ (子要素コメント処理命令など) を処理できませんが、複数隣接したテキスト ブロックと CDATA ブロック連結できます

このメソッド呼び出すと、EndElement ノード次のノードまたは空の要素タグ後ろリーダー配置されます。

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

XmlReader.ReadElementString メソッド

XmlReader による XML読み取り


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

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

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

XmlReader.ReadElementString メソッド ()のお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS