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

Dim instance As XmlAttribute Dim deep As Boolean Dim returnValue As XmlNode returnValue = instance.CloneNode(deep)
戻り値
複製されたノード。

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

CloneNode を使用して、属性を 2 つの異なる要素のノードに追加する例を次に示します。
Imports System Imports System.IO Imports System.Xml public class Sample public shared sub Main() Dim doc as XmlDocument = new XmlDocument() doc.Load("2elems.xml") 'Create an attribute. Dim attr as XmlAttribute attr = doc.CreateAttribute("bk","genre" ,"urn:samples") attr.Value = "novel" 'Add the attribute to the first book. Dim currNode as XmlElement currNode = CType(doc.DocumentElement.FirstChild, XmlElement) currNode.SetAttributeNode(attr) 'An attribute cannot be added to two different elements. 'You must clone the attribute and add it to the second book. Dim attr2 as XmlAttribute attr2 = CType (attr.CloneNode(true), XmlAttribute) currNode = CType(doc.DocumentElement.LastChild, XmlElement) currNode.SetAttributeNode(attr2) Console.WriteLine("Display the modified XML...") Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out) writer.Formatting = Formatting.Indented doc.WriteContentTo(writer) end sub end class
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { //Create an XmlDocument. XmlDocument doc = new XmlDocument(); doc.Load("2elems.xml"); //Create an attribute. XmlAttribute attr; attr = doc.CreateAttribute("bk","genre","urn:samples"); attr.Value = "novel"; //Add the attribute to the first book. XmlElement currNode = (XmlElement) doc.DocumentElement.FirstChild; currNode.SetAttributeNode(attr); //An attribute cannot be added to two different elements. //You must clone the attribute and add it to the second book. XmlAttribute attr2; attr2 = (XmlAttribute) attr.CloneNode(true); currNode = (XmlElement) doc.DocumentElement.LastChild; currNode.SetAttributeNode(attr2); Console.WriteLine("Display the modified XML...\r\n"); XmlTextWriter writer = new XmlTextWriter(Console.Out); writer.Formatting = Formatting.Indented; doc.WriteContentTo(writer); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { //Create an XmlDocument. XmlDocument^ doc = gcnew XmlDocument; doc->Load( "2elems.xml" ); //Create an attribute. XmlAttribute^ attr; attr = doc->CreateAttribute( "bk", "genre", "urn:samples" ); attr->Value = "novel"; //Add the attribute to the first book. XmlElement^ currNode = dynamic_cast<XmlElement^>(doc->DocumentElement->FirstChild); currNode->SetAttributeNode( attr ); //An attribute cannot be added to two different elements. //You must clone the attribute and add it to the second book. XmlAttribute^ attr2; attr2 = dynamic_cast<XmlAttribute^>(attr->CloneNode( true )); currNode = dynamic_cast<XmlElement^>(doc->DocumentElement->LastChild); currNode->SetAttributeNode( attr2 ); Console::WriteLine( "Display the modified XML...\r\n" ); XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out ); writer->Formatting = Formatting::Indented; doc->WriteContentTo( writer ); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { public static void main(String[] args) { //Create an XmlDocument. XmlDocument doc = new XmlDocument(); doc.Load("2elems.xml"); //Create an attribute. XmlAttribute attr; attr = doc.CreateAttribute("bk", "genre", "urn:samples"); attr.set_Value("novel"); //Add the attribute to the first book. XmlElement currNode = (XmlElement)doc.get_DocumentElement().get_FirstChild(); currNode.SetAttributeNode(attr); //An attribute cannot be added to two different elements. //You must clone the attribute and add it to the second book. XmlAttribute attr2; attr2 = (XmlAttribute)attr.CloneNode(true); currNode = (XmlElement)doc.get_DocumentElement().get_LastChild(); currNode.SetAttributeNode(attr2); Console.WriteLine("Display the modified XML...\r\n"); XmlTextWriter writer = new XmlTextWriter(Console.get_Out()); writer.set_Formatting(Formatting.Indented); doc.WriteContentTo(writer); } //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に収録されているすべての辞書からXmlAttribute.CloneNode メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlAttribute.CloneNode メソッドのページへのリンク