XmlReader.ReadInnerXml メソッド

定義

派生クラスでオーバーライドされると、マークアップを含むすべての内容を文字列として読み取ります。

public:
 virtual System::String ^ ReadInnerXml();
public virtual string ReadInnerXml ();
abstract member ReadInnerXml : unit -> string
override this.ReadInnerXml : unit -> string
Public Overridable Function ReadInnerXml () As String

戻り値

現在のノード内の、マークアップを含むすべての XML の内容。 現在のノードが子を持っていない場合は、空の文字列が返されます。

現在のノードが要素でも属性でもない場合は、空の文字列が返されます。

例外

XML が整形式ではありませんでした。または、XML の解析中にエラーが発生しました。

先行の非同期操作が完了する前に、XmlReader メソッドが呼び出されました。 この場合、「非同期操作が既に実行されています」というメッセージと共に InvalidOperationException がスローされます。

次の例では、 メソッドと ReadOuterXml メソッドをReadInnerXml比較します。

// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create("2books.xml")) {

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

  // Moves to book node.
  reader.Read();

  // Note that ReadInnerXml only returns the markup of the node's children
  // so the book's attributes are not returned.
  Console.WriteLine("Read the first book using ReadInnerXml...");
  Console.WriteLine(reader.ReadInnerXml());

  // ReadOuterXml returns the markup for the current node and its children
  // so the book's attributes are also returned.
  Console.WriteLine("Read the second book using ReadOuterXml...");
  Console.WriteLine(reader.ReadOuterXml());
}
' Load the file and ignore all white space.
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using reader As XmlReader = XmlReader.Create("2books.xml")

  ' Moves the reader to the root element.
  reader.MoveToContent()
                
  ' Moves to book node.
  reader.Read()
                
  ' Note that ReadInnerXml only returns the markup of the node's children
  ' so the book's attributes are not returned.
  Console.WriteLine("Read the first book using ReadInnerXml...")
  Console.WriteLine(reader.ReadInnerXml())
                
  ' ReadOuterXml returns the markup for the current node and its children
  ' so the book's attributes are also returned.
  Console.WriteLine("Read the second book using ReadOuterXml...")
  Console.WriteLine(reader.ReadOuterXml())

End Using

この例では、入力としてファイルを使用 2books.xml します。

<!--sample XML fragment-->
<bookstore>
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
    <price>19.95</price>
  </book>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>
    <price>24.95</price>
  </book>
</bookstore>

注釈

このメソッドは、マークアップを含む現在のノードのすべてのコンテンツを返します。 現在のノード (開始タグ) と対応する終了ノード (終了タグ) は返されません。 たとえば、次のような場合です。

<node>
 this <child id="123"/>
</node>

ReadInnerXmlthis <child id="123"/> を返します。

このメソッドは、次の方法で要素ノードと属性ノードを処理します。

ノード型 呼び出し前の位置 XML フラグメント 戻り値 呼び出し後の位置
Element item1 開始タグ上。 <item1>text1</item1><item2>text2</item2> text1 item2 開始タグ上。
Attribute attr1 属性ノード上。 <item attr1="val1" attr2="val2">text</item> val1 attr1 属性ノード上に留まる。

リーダーがリーフ ノード上にある場合、ReadInnerXml の呼び出しは Read と同じです。 メソッドは を返します String.Empty (属性ノードを除き、その場合、 属性の値が返されます)。

このメソッドは、整形式 XML をチェックします。 が からXmlValidatingReader呼び出された場合ReadInnerXml、このメソッドは返されるコンテンツも検証します。

および クラスにXmlNodeReaderXmlTextReaderXmlValidatingReader実装されているように、 ReadOuterXml メソッドは名前空間に対応しています。

このメソッドの非同期バージョンについては、「」を参照してください ReadInnerXmlAsync

適用対象