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
|