473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can an XmlNode from one XmlDocument be copied to another XmlDocument?

Bob
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?
Nov 18 '05 #1
3 6111
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)

" Bob" <bo*******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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?

Nov 18 '05 #2
Bob wrote:
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


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]
http://blog.tkachenko.com
Nov 18 '05 #3
Bob
I tried InnerXml and it works. Since you mentioned performance, is it
particularly slow?

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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)

" Bob" <bo*******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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?


Nov 18 '05 #4

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

Similar topics

3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
4
by: Rune | last post by:
I have two queries that appear to be exactly the same, but one of them returns null while the other one returns a valid result! Can anyone provide an explanation to why this is so? Below is an...
3
by: Bob | last post by:
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...
2
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString"...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
3
by: Earl | last post by:
In VB.Net, the following declaration builds and executes with no exceptions: Dim XMLDoc As New XmlDocument Dim Node As XmlNode But in C#, the following (equivalent?!) returns the build error...
5
by: GaryDean | last post by:
I have a web service method that returns an XMLDocument. The signature is: public XmlDocument GetPOs() The following client code calls this method but it accepts an XMLNode instead of an...
1
by: Andrus | last post by:
How to remove whole Xmlnode so that outer tags are also removed ? To reproduce, run the code. Observed result: <Query> <DataSourceName>DS1</DataSourceName> <QueryParameters>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.