XmlReader.ReadOuterXml メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlReader Dim returnValue As String returnValue = instance.ReadOuterXml
リーダーが要素ノードまたは属性ノードに配置されている場合、このメソッドは、現在のノードおよびそのすべての子の、マークアップを含む、XML の内容をすべて返します。それ以外の場合は、空の文字列を返します。


このメソッドは、開始タグと終了タグを返す点を除くと、ReadInnerXml に似ています。
このメソッドは、要素ノードおよび属性ノードを次の方法で処理します。
ノード型 | ||||
---|---|---|---|---|
<item1>text1</item1><item2>text2</item2> | <item1>text1</item1> | |||
attr1="val1" |
リーダーをリーフ ノードに配置すると、ReadOuterXml の呼び出しは、Read の呼び出しに等しくなります。メソッドは String.Empty を返します (ただし、属性ノードの場合は属性マークアップを返します)。
このメソッドは、整形式の XML かどうかをチェックします。ReadOuterXml が XmlValidatingReader から呼び出された場合、返された内容も検証します。
ReadOuterXml メソッドは、XmlNodeReader クラス、XmlTextReader クラス、および XmlValidatingReader クラスで実装されるため、名前空間を認識します。XML テキスト <A xmlns:S="urn:1"><S:B>hello</S:B></A> を指定した場合、リーダーを S:B 開始タグ上に配置すると、ReadOuterXml は <S:B xmlns:S="urn:1">hello<S:B/> を返します。

ReadInnerXml メソッドと 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
// 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()); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlReader.ReadOuterXml メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlReader.ReadOuterXml メソッドのページへのリンク