Re: AppendChild of diff document

Tech-Archive recommends: Fix windows errors by optimizing your registry



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/
.



Relevant Pages

  • AppendChild of diff document
    ... Trying to select a node 'E' from XML document 'ParentXML' and append the ... XmlDocument ParentXML= new XmlDocument; ... XmlDocument ChildXML = new XmlDocument; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Covert a document with Qualified elements to Unqualified Elements
    ... "Qualified" elements into an XML document without Qualified Elements. ... Martin Honnen --- MVP XML ...
    (microsoft.public.dotnet.xml)
  • Re: Dataset.readxml failing
    ... Sriram Surapureddy wrote: ... where obviously ISO-8859-1 is just an example, I don't know which encoding your XML document has. ... Martin Honnen --- MVP XML ...
    (microsoft.public.dotnet.xml)
  • Re: XML Help
    ... Mike Fellows wrote: ... doucmentation for the XML document that I have been given wants me to create a xml document with the following: ... Martin Honnen --- MVP XML ...
    (microsoft.public.dotnet.languages.vb)