Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 2nd, 2003, 05:48 PM
Registered User
 
Join Date: Nov 2003
Location: Bournemouth, Dorset, United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copying XML nodes from one document to another

Hi there.

I'm quite new to c#, and I need some help!

I have two XmlDocuments. I want to copy the contents of document 2 into document 1. I have tried getting the 1st node of document two, and appending it to the top level node of document 1, but keep getting an error about different document contexts.

Doc 1 looks like this
<?xml version="1.0" encoding="utf-8" ?>
<switches>
</switches>

Doc 2 looks like this
<?xml version="1.0" encoding="utf-8" ?>
<switch>
   <switchid>21</switchid>
   <switchDescription>Hughs PC (from ini)</switchDescription>
   <switchCapability>15</switchCapability>
   <switchDeploymentId>Laptop PC</switchDeploymentId>
   <SwitchSubscribers>
      <subscriber>
         <name>2001 mux1 (switch 1)</name>
         <logicalNumber>1202001</logicalNumber>
         <physicalNumber>2001</physicalNumber>
         <link>1</link>
         <security>1</security>
         <pin>1101</pin>
         <alias>Subscriber 1202001</alias>
         <minPrec>0</minPrec>
         <maxPrec>0</maxPrec>
         <divert>0</divert>
         <divertDelay>0</divertDelay>
         <hotline>0</hotline>
         <facilities>0</facilities>
         <subscriberType>Sentinel</subscriberType>
         <preemptable>1</preemptable>
      </subscriber>
   </SwitchSubscribers>
</switch>


What I want doc 1 to end up like is this :-

<?xml version="1.0" encoding="utf-8" ?>
<switches>
   <switch>
      <switchid>21</switchid>
      <switchDescription>Hughs PC (from ini)</switchDescription>
      <switchCapability>15</switchCapability>
      <switchDeploymentId>Laptop PC</switchDeploymentId>
      <SwitchSubscribers>
        <subscriber>
            <name>2001 mux1 (switch 1)</name>
            <logicalNumber>1202001</logicalNumber>
            <physicalNumber>2001</physicalNumber>
            <link>1</link>
            <security>1</security>
            <pin>1101</pin>
            <alias>Subscriber 1202001</alias>
            <minPrec>0</minPrec>
            <maxPrec>0</maxPrec>
            <divert>0</divert>
            <divertDelay>0</divertDelay>
            <hotline>0</hotline>
            <facilities>0</facilities>
            <subscriberType>Sentinel</subscriberType>
            <preemptable>1</preemptable>
         </subscriber>
      </SwitchSubscribers>
   </switch>
</switches>

Each <switch> entry may be followed by other <switch> entries.

Can anyone help?

Thanks in advance
  #2 (permalink)  
Old December 3rd, 2003, 09:12 AM
Registered User
 
Join Date: Nov 2003
Location: Bournemouth, Dorset, United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's ok - I've found the answer on google...
  #3 (permalink)  
Old May 12th, 2005, 01:20 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need to do something similar. Where did you find the solution?



Similar Threads
Thread Thread Starter Forum Replies Last Post
copying xml attributes golddog XSLT 1 September 12th, 2007 01:05 PM
problem accessing nodes using document() and id() siris phi XSLT 3 April 12th, 2007 11:05 PM
Problem Copying Nodes tclotworthy XSLT 14 February 13th, 2007 01:13 PM
Problem copying XML nodes francislang XSLT 9 October 21st, 2005 10:37 AM
Add and Remove Nodes in XML document. tutul128 XML 3 March 1st, 2004 10:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.