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

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

XmlDocumentFragment.CloneNode メソッド

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

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

Public Overrides Function
 CloneNode ( _
    deep As Boolean _
) As XmlNode
Dim instance As XmlDocumentFragment
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指定したノードだけのクローン作成する場合false

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

解説解説

CloneNode は、ノードコピー コンストラクタとして機能します。このメソッドが他のノード種類ではどのように動作するかを確認するには、XmlNode.CloneNode のトピック参照してください

クローンとして作成されノードには親がありません。ParentNode は null 参照 (Visual Basic では Nothing) を返します

使用例使用例

詳細クローン簡易クローン違いの例を次に示します

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
    
    ' Create the XmlDocument.
    Dim doc as XmlDocument  = new
 XmlDocument()
    doc.LoadXml("<items/>")

    ' Create a document fragment.
    Dim docFrag as XmlDocumentFragment = doc.CreateDocumentFragment()

    ' Set the contents of the document fragment.
    docFrag.InnerXml ="<item>widget</item>"

    ' Create a deep clone.  The cloned node
    ' includes child nodes.
    Dim deep as XmlNode = docFrag.CloneNode(true)
    Console.WriteLine("Name: " + deep.Name)
    Console.WriteLine("OuterXml: " + deep.OuterXml)

    ' Create a shallow clone.  The cloned node does
    ' not include any child nodes.
    Dim shallow as XmlNode = docFrag.CloneNode(false)
    Console.WriteLine("Name: " + shallow.Name)
    Console.WriteLine("OuterXml: " + shallow.OuterXml)
    

  end sub
end class
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    
    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<items/>");

    // Create a document fragment.
    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();

    // Set the contents of the document fragment.
    docFrag.InnerXml ="<item>widget</item>";

    // Create a deep clone.  The cloned node
    // includes child nodes.
    XmlNode deep = docFrag.CloneNode(true);
    Console.WriteLine("Name: " + deep.Name);
    Console.WriteLine("OuterXml: " + deep.OuterXml);

    // Create a shallow clone.  The cloned node does
    // not include any child nodes.
    XmlNode shallow = docFrag.CloneNode(false);
    Console.WriteLine("Name: " + shallow.Name);
    Console.WriteLine("OuterXml: " + shallow.OuterXml);    

  }
}
#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( "<items/>" );
   
   // Create a document fragment.
   XmlDocumentFragment^ docFrag = doc->CreateDocumentFragment();
   
   // Set the contents of the document fragment.
   docFrag->InnerXml = "<item>widget</item>";
   
   // Create a deep clone.  The cloned node
   // includes child nodes.
   XmlNode^ deep = docFrag->CloneNode( true );
   Console::WriteLine( "Name: {0}", deep->Name );
   Console::WriteLine( "OuterXml: {0}", deep->OuterXml );
   
   // Create a shallow clone.  The cloned node does
   // not include any child nodes.
   XmlNode^ shallow = docFrag->CloneNode( false );
   Console::WriteLine( "Name: {0}", shallow->Name );
   Console::WriteLine( "OuterXml: {0}", shallow->OuterXml );
}

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("<items/>");

        // Create a document fragment.
        XmlDocumentFragment docFrag = doc.CreateDocumentFragment();

        // Set the contents of the document fragment.
        docFrag.set_InnerXml("<item>widget</item>");

        // Create a deep clone.  The cloned node
        // includes child nodes.
        XmlNode deep = docFrag.CloneNode(true);
        Console.WriteLine("Name: " + deep.get_Name());
        Console.WriteLine("OuterXml: " + deep.get_OuterXml());

        // Create a shallow clone.  The cloned node does
        // not include any child nodes.
        XmlNode shallow = docFrag.CloneNode(false);
        Console.WriteLine("Name: " + shallow.get_Name());
        Console.WriteLine("OuterXml: " + shallow.get_OuterXml());
    } //main 
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlDocumentFragment クラス
XmlDocumentFragment メンバ
System.Xml 名前空間


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS