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

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

XmlElement.CloneNode メソッド

このノード複製作成します

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

Public Overrides Function
 CloneNode ( _
    deep As Boolean _
) As XmlNode
Dim instance As XmlElement
Dim deep As Boolean
Dim returnValue As XmlNode

returnValue = instance.CloneNode(deep)
public override XmlNode CloneNode (
    bool deep
)
public:
virtual XmlNode^ CloneNode (
    bool deep
) override
public XmlNode CloneNode (
    boolean deep
)
public override function CloneNode (
    deep : boolean
) : XmlNode

パラメータ

deep

指定したノードの下にあるサブツリーのクローン再帰的作成する場合true指定したノードだけ (および、そのノードXmlElement場合はその属性) のクローン作成する場合false

戻り値
クローンとして作成されノード

解説解説

このメソッドは、ノードコピー コンストラクタとして機能します複製されノードには親がありません。ParentNode は null 参照 (Visual Basic では Nothing) を返します

使用例使用例

新し要素作成し、そのクローン作成して両方要素XML ドキュメント追加する例を次に示します

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        
        Dim doc As New XmlDocument()
        doc.Load("2books.xml")
        
        ' Create a new element.
        Dim elem As XmlElement = doc.CreateElement("misc")
        elem.InnerText = "hardcover"
        elem.SetAttribute("publisher", "WorldWide
 Publishing")
        
        ' Clone the element so we can add one to each of the book nodes.
        Dim elem2 As XmlNode = elem.CloneNode(True)
        
        ' Add the new elements.
        doc.DocumentElement.FirstChild.AppendChild(elem)
        doc.DocumentElement.LastChild.AppendChild(elem2)
        
        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()
  {

    XmlDocument doc = new XmlDocument();
    doc.Load("2books.xml");

    // Create a new element.
    XmlElement elem = doc.CreateElement("misc");
    elem.InnerText = "hardcover";
    elem.SetAttribute("publisher", "WorldWide Publishing");

    // Clone the element so we can add one to each of the book nodes.
    XmlNode elem2 = elem.CloneNode(true);

    // Add the new elements.
    doc.DocumentElement.FirstChild.AppendChild(elem);
    doc.DocumentElement.LastChild.AppendChild(elem2);

    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()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "2books.xml" );
   
   // Create a new element.
   XmlElement^ elem = doc->CreateElement( "misc" );
   elem->InnerText = "hardcover";
   elem->SetAttribute( "publisher", "WorldWide Publishing"
 );
   
   // Clone the element so we can add one to each of the book nodes.
   XmlNode^ elem2 = elem->CloneNode( true );
   
   // Add the new elements.
   doc->DocumentElement->FirstChild->AppendChild( elem );
   doc->DocumentElement->LastChild->AppendChild( elem2 );
   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)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("2books.xml");

        // Create a new element.
        XmlElement elem = doc.CreateElement("misc");
        elem.set_InnerText("hardcover");
        elem.SetAttribute("publisher", "WorldWide Publishing");

        // Clone the element so we can add one to each of the book nodes.
        XmlNode elem2 = elem.CloneNode(true);

        // Add the new elements.
        doc.get_DocumentElement().get_FirstChild().AppendChild(elem);
        doc.get_DocumentElement().get_LastChild().AppendChild(elem2);
    
        Console.WriteLine("Display the modified XML...");
        doc.Save(Console.get_Out());
    } //main 
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS