copy Xml to Xml files
-
Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)
-
Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)
You need to create a new node and copy it into the new document, otherwise, the same node ( as it's passed by reference ) is in two documents, and this is verboten.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi! i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node). I always get the error that this node belongs to another xml document: "the node to be inserted is from a diffrent document content" how should i do this copy?? Thanks :)
You must first Import the node from another doc to yours,you can do that using ImportNode method from from XmlDocumrent instance so it would be somewhat like this and if you want to create a whole new coy of your node pass deep argument as true otherwise just the selected node would be impoterd not the childs
XmlDocument doc1 = new XmlDocument();
doc1.AppendChild(doc1.CreateElement("MyElement"));
doc1.Save(@"N:\doc1.xml");XmlDocument doc2 = new XmlDocument();
XmlNode importedNode = doc2.ImportNode(doc1["MyElement"], true);
doc2.AppendChild(importedNode);
doc2.Save(@"N:\doc2.xml");good luck