PC Review


Reply
Thread Tools Rate Thread

AppendChild of diff document

 
 
Praveen
Guest
Posts: n/a
 
      12th Feb 2007
Trying to select a node 'E' from XML document 'ParentXML' and append the
same to another xml document 'ChildXML'


string MyXMLStr="<R><E A='1'/></R>";
XmlDocument ParentXML= new XmlDocument();
ParentXML.LoadXml(MyXMLStr);




XmlDocument ChildXML = new XmlDocument();
ChildXML.LoadXml("<R/>");

XmlElement tempE = (XmlElement) ParentXML.DocumentElement.SelectSingleNode
("E");

ChildXML.DocumentElement.AppendChild(tempE);


throws 'The node to be inserted is from a different document context.'
error.

Can I use Clone() or CloneNode() to achieve this.
A sample will be usefull.

hanks,
praveen



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12th Feb 2007
Praveen wrote:
> Trying to select a node 'E' from XML document 'ParentXML' and append the
> same to another xml document 'ChildXML'
>
>
> string MyXMLStr="<R><E A='1'/></R>";
> XmlDocument ParentXML= new XmlDocument();
> ParentXML.LoadXml(MyXMLStr);
>
>
>
>
> XmlDocument ChildXML = new XmlDocument();
> ChildXML.LoadXml("<R/>");
>
> XmlElement tempE = (XmlElement) ParentXML.DocumentElement.SelectSingleNode
> ("E");
>
> ChildXML.DocumentElement.AppendChild(tempE);


You need to use ImportNode
ChildXML.DocumentElement.AppendChild(ChildXML.ImportNode(tempE, true));

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
different margins in 2 diff pages - 1 document in word =?Utf-8?B?bWF2eUBkaXNjdXNzaW9ucy5taWNyb3NvZg==?= Microsoft Word Document Management 7 12th Jun 2006 10:00 PM
different margins in 2 diff pages - 1 document in word =?Utf-8?B?bWF2eUBkaXNjdXNzaW9ucy5taWNyb3NvZg==?= Microsoft Word Document Management 0 8th Jun 2006 11:04 PM
AppendChild removes like nodes? =?Utf-8?B?YmVhbndlZWQ=?= Microsoft ASP .NET 1 1st Mar 2005 05:39 PM
XML Can't AppendChild =?Utf-8?B?Sm9u?= Microsoft Dot NET Framework 0 26th Feb 2004 02:46 PM
Re: img object and appendChild problem Intersoft Corp. Windows XP Internet Explorer 0 5th Sep 2003 11:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:58 PM.