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

Dim instance As XmlDocument Dim reader As XmlReader Dim returnValue As XmlNode returnValue = instance.ReadNode(reader)
戻り値
新しい XmlNode。ノードがそれ以上存在しない場合は null 参照 (Visual Basic では Nothing)。


指定したリーダーから 1 つの XmlNode を読み取り、そのリーダーを次のノードに配置します。このメソッドは、リーダーが現在配置されている NodeType に一致する XmlNode の型を作成します。リーダーが初期状態にある場合、ReadNode はリーダーを最初のノードに進めて、そのノード上で動作します。
リーダーが要素の先頭に配置されている場合、ReadNode は、現在のノードの終了タグを含め、その終了タグまでのすべての属性および子ノードを読み取ります。返された XmlNode には、読み取ったすべての内容を表すサブツリーが含まれます。リーダーは終了タグの直後に配置されます。
ReadNode も属性を読み取りますが、この場合は、リーダーを次の属性に進めません。これにより、次の C# コードを書き込むことができます。
XmlDocument doc = new XmlDocument(); while (reader.MoveToNextAttribute()) { XmlNode a = doc.ReadNode(reader); // Do some more processing. }
ReadNode は属性値を使用しますが、1 つの属性で ReadNode を呼び出した後は、XmlReader.ReadAttributeValue は false を返します。
継承時の注意 このメソッドには継承確認要求があります。ReadNode メソッドをオーバーライドするには、完全な信頼が必要です。詳細については、「継承確認要求」を参照してください。 このメソッドは、DOM (Document Object Model) に対する Microsoft 拡張機能です。
ReadNode を使用して新しいノードを作成し、そのノードをドキュメントに挿入する例を次に示します。
Option Explicit Option Strict Imports System Imports System.IO Imports System.Xml Public Class Sample Public Shared Sub Main() 'Create the XmlDocument. Dim doc As New XmlDocument() doc.LoadXml("<bookstore>" & _ "<book genre='novel' ISBN='1-861001-57-5'>" & _ "<title>Pride And Prejudice</title>" & _ "</book>" & _ "</bookstore>") 'Create a reader. Dim reader As New XmlTextReader("cd.xml") reader.MoveToContent() 'Move to the cd element node. 'Create a node representing the cd element node. Dim cd As XmlNode = doc.ReadNode(reader) 'Insert the new node into the document. doc.DocumentElement.AppendChild(cd) Console.WriteLine("Display the modified XML...") doc.Save(Console.Out) End Sub 'Main End Class 'Sample
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { //Create the XmlDocument. XmlDocument doc = new XmlDocument(); doc.LoadXml("<bookstore>" + "<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>" + "</bookstore>"); //Create a reader. XmlTextReader reader = new XmlTextReader("cd.xml"); reader.MoveToContent(); //Move to the cd element node. //Create a node representing the cd element node. XmlNode cd = doc.ReadNode(reader); //Insert the new node into the document. doc.DocumentElement.AppendChild(cd); Console.WriteLine("Display the modified XML..."); doc.Save(Console.Out); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { //Create the XmlDocument. XmlDocument^ doc = gcnew XmlDocument; doc->LoadXml( "<bookstore><book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book></bookstore>" ); //Create a reader. XmlTextReader^ reader = gcnew XmlTextReader( "cd.xml" ); reader->MoveToContent(); //Move to the cd element node. //Create a node representing the cd element node. XmlNode^ cd = doc->ReadNode( reader ); //Insert the new node into the document. doc->DocumentElement->AppendChild( cd ); Console::WriteLine( "Display the modified XML..." ); doc->Save( Console::Out ); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { public static void main(String[] args) { //Create the XmlDocument. XmlDocument doc = new XmlDocument(); doc.LoadXml("<bookstore>" + "<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>" + "</bookstore>"); //Create a reader. XmlTextReader reader = new XmlTextReader("cd.xml"); reader.MoveToContent(); //Move to the cd element node. //Create a node representing the cd element node. XmlNode cd = doc.ReadNode(reader); //Insert the new node into the document. doc.get_DocumentElement().AppendChild(cd); Console.WriteLine("Display the modified XML..."); doc.Save(Console.get_Out()); } //main } //Sample

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に収録されているすべての辞書からXmlDocument.ReadNode メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlDocument.ReadNode メソッドのページへのリンク