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

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

XmlDocument.ReadNode メソッド

XmlReader 内の情報基づいて、XmlNode オブジェクト作成しますリーダーは、ノードまたは属性配置されている必要があります

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

Public Overridable Function
 ReadNode ( _
    reader As XmlReader _
) As XmlNode
Dim instance As XmlDocument
Dim reader As XmlReader
Dim returnValue As XmlNode

returnValue = instance.ReadNode(reader)
public virtual XmlNode ReadNode (
    XmlReader reader
)
public:
virtual XmlNode^ ReadNode (
    XmlReader^ reader
)
public XmlNode ReadNode (
    XmlReader reader
)
public function ReadNode (
    reader : XmlReader
) : XmlNode

パラメータ

reader

XML ソース

戻り値
新しXmlNodeノードそれ以上存在しない場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

InvalidOperationException

リーダーが、EndElement や EndEntity など、有効な DOM ノード変換されないノード型に配置されています。

解説解説

指定したリーダーから 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

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

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


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS