Groups | Blog | Home
all groups > dotnet xml > july 2004 >

dotnet xml : Can an XmlNode from one XmlDocument be copied to another XmlDocument?


bruce barker
7/20/2004 10:40:11 AM
you have to build a new node and create your own copy function. if
performance is not the top issue, use the InnerXml/OuterXml properties to
copy.

-- bruce (sqlwork.com)



[quoted text, click to view]

Bob
7/20/2004 11:50:13 AM
I'm wondering if one node that belongs to one XmlDocument can be appended to
another XmlDocument as a new child without having to build a new node from
scratch. I would think XmlNode.Clone() is for this purpose but no, it
doesn't work. I got the following error:

The node to be inserted is from a different document context

Does anyone know if this is doable without building a new node and without
putting through XSL?

Oleg Tkachenko [MVP]
7/20/2004 9:57:18 PM
[quoted text, click to view]

You have to import a node before inserting it:

XmlNode newBook = doc.ImportNode(doc2.DocumentElement.LastChild, true);
doc.DocumentElement.AppendChild(newBook);

--
Oleg Tkachenko [XML MVP]
Bob
7/21/2004 6:49:14 PM
I tried InnerXml and it works. Since you mentioned performance, is it
particularly slow?

[quoted text, click to view]

AddThis Social Bookmark Button