473,804 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clone xml node for an other document

Hi

How is it possible to copy or clone a node from a given document to an other
document .

Here is my method :

static void test(XmlDocumen t doc1,XmlDocumen t doc2)

{

XmlNode node2 = doc2.CreateElem ent("node2");

XmlNode root1 = doc1["root"];

root1.AppendChi ld(node2);//exception thrown : inserted node comes from an
other document context

root1.OwnerDocu ment.Save("targ et.xml");

}

Thanks for advice

David
May 11 '06 #1
1 3178


Davidoff wrote:

How is it possible to copy or clone a node from a given document to an other
document .


You need to use ImportNode, a method of an XmlDocument e.g.
node1.AppendChi ld(node1.OwnerD ocument.ImportN ode(node2, true))

See the documentation here:

<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/cpref/html/frlrfSystemXmlX mlDocumentClass ImportNodeTopic .asp>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2672
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some not so obvious errors I have made.. Cheers
2
1750
by: ricky | last post by:
i have this xml document: <order> <item occur="unbounded"> <ref>122</ref> <name>bla bla</name> </item> <item occur="unbounded"> <ref>122</ref> <name>bla bla</name> </item>
2
6612
by: Andy Fish | last post by:
Hi, I am trying to figure out how to make a complete copy of a DOM document. I am using xerces but vanilla DOM would obviously be the best solution. The nearest I have got is something like: Document newDoc = new DocumentImpl(); newDoc.appendChild(newDoc.importNode(oldDoc.getDocumentElement(),true));
2
4468
by: bclegg | last post by:
Hi, When I implement the example code it errors with 'No parameterless constructor defined for this object.' experimenting with dim o as object = mytreenode.clone() gives the same error. The example code is: Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
6
6748
by: jw | last post by:
hi all i have a binary tree and want to clone this, is there a standard way to do this,i think i can do it by traversing the tree like in the preorder tecnique and add all the nodes to another root is there a common way to do this?
1
3823
by: Alex D. | last post by:
hi guys. I need to clone multiple times an object and I am succesfully cloning using the regular serialization process, using a MemoryStream. My problem is that after cloning the object more that 7 or 10 times then my computer's memory gets flooded and every time I call the Clone() method the processor resources gets consumed 100% for like 30 seconds. And this problem increases as the amount of clones are created increases. I read some...
2
11472
by: Steven | last post by:
Hi, I have created my own node (class MyNode : TreeNode) for a TreeView. To populate the treeview, i use something like MyNode newNode = new MyNode("Bla bla bla","0","1") for example. But, to move the nodes in the treeview, i use the clone() method... : MyNode theCopy = (MyNode)theTreeView.SelectedNode.Clone();
1
6685
by: jaktharkhan | last post by:
Hi, I really really need help in trying to figure out how can I do a CloneNode on an Iframe where the cloned IFRAME clones with all its contents?. Basically what I am doing is dynamically building a table with Iframes inside it. The problem is I just want to build one Iframe because the contents of it can be very complex. After my Iframe is built I just want to clone the iframe as many times as I need later. I cannot use an HTML file and...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.