473,656 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding elements of XmlDocument A in XmlDocument B

Hello,

I want to add some elements of one XmlDocument in another.
My code looks like this:

XmlDocument docA= new XmlDocument();
docA.LoadXml(re cord);
XmlNodeList nl = docA.SelectNode s("/search/recordlist/record");

XmlNode recordlist = docB.FirstChild ;

foreach (XmlNode node in nl)
{
recordlist.Appe ndChild(node);
}
But these lines of code do not work,
because the compiler tells me:

"The node to be inserted is from a different document context."
How can I solve this problem?

Regards,

Martin
Nov 21 '06 #1
2 1682

recordlist.Appe ndChild(docB.Im portNode(node,t rue));

Marc
Nov 21 '06 #2
Martin Pöpping wrote:
Hello,

I want to add some elements of one XmlDocument in another.
My code looks like this:

XmlDocument docA= new XmlDocument();
docA.LoadXml(re cord);
XmlNodeList nl = docA.SelectNode s("/search/recordlist/record");

XmlNode recordlist = docB.FirstChild ;

foreach (XmlNode node in nl)
{
recordlist.Appe ndChild(node);
You need to use ImportNode
recordList.Appe ndChild(recordl ist.OwnerDocume nt.ImportNode(n ode,
true));
Note that ImportNode will create a copy of the node to be imported so
the code above will not remove the nodes from document A.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '06 #3

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

Similar topics

3
1728
by: gordon.lear | last post by:
I am using MSXML 4.0 I am grabbing numerous RSS News Feeds and trying to parse the data and read it into a dB. The problem is that the RSS News feeds are not all the same when tunneled down in the item element. They ALL contain the nodes: title, description, link and pubDate. But they come in all different orders and have other child nodes sandwiched among the ones I am after.
6
6065
by: Pavils Jurjans | last post by:
Hello, Here's the sample XML: <sample1></sample1> <sample2/> From many XML books and online documentations, it is said to be just different syntax for the same data. However, when we analyze the node
2
2360
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void SchemaValidate(XmlDocument xmlDoc, string schemaURI, string urnNamespace) {
1
1680
by: Geir Sørensen | last post by:
Hi, When I transform an xml-file using XslTransform, I seem to get a lot of elements of this form: <a> </a> <b> </b> But I really would like to get written out like I do when transforming with MSXML, where I get
2
9122
by: Thirsty Traveler | last post by:
How would I dynamcially create an XML document of the following form: <ReceiveTSSCallBack xmlns="http://LandAm.EAI.Mainframe.TSR"> <TSSCallBack xmlns="http://LandAm.EAI.Mainframe.TSR.Schemas.TSSCallback"> <orderNo xmlns="">string</orderNo> <customerId xmlns="">string</customerId> <taxingAuthorityList xmlns=""> <string>string</string> <string>string</string>
6
1893
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def> <Elements> <Element att1="1" att2="2" att3="3" //Some attributes are
2
5137
by: BillGatesFan | last post by:
Is there anyway to read a collection of xml elements in .NET? The XML Reader class does not seem like it can do it. It reads the file sequentially. I want to read an xml file and get the collection of elements named book. The for each book element I want to get its attributes and inner element attributes. Can this be done? Now it seems like you have to call readnextelement multiple times.
7
15279
by: MaxMax | last post by:
I want to insert a white line between XML elements to raise human readability example: <MyNode> </MyNode> <MyNode> </MyNode>
11
2306
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to add the following attributes (xmlns:xsi and xsi:type) to a node (Grantee) like the following: <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group"> <URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI> </Grantee> However I am unclear on how to add these types of attributes. The following doesn't seem to work.
0
8297
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
8816
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
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
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
7311
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...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1600
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.