473,406 Members | 2,312 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,406 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 12 '05 #1
3 5882
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 12 '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 12 '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 12 '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 =...
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: 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...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.