Last post Jun 23, 2011 03:40 AM by narenderrawal007
Jun 22, 2011 06:52 AM|narenderrawal007|LINK
I have an xml file(main file) which I have to wipe off and copy its data to other xml file (back up file)on click of a button. I have been able to delete the data, I have been able to get everynode of subroot of main xml file but I do not know how to export
it to other file. I just have to append the nodes to back up file.
Here is the code which I am using to delete the xml details from xml node ?
XMLdocument doc = new xml document();
XmlNodeList NodeList = doc.getElmentsbyTagName("subroot");
// delete all the nodes, here I have acess to all the nodes
Using above code I am able to delete the data. I have access to all the nodes using NodeList. All I have to do is to just copy all those nodes to back up xml file.
I think I am just missing a small piece. Can anyone help.
Jun 22, 2011 07:33 AM|chandrashekar|LINK
After you delete all the nodes which are not required, create a new XMLDocument class instance and load the updated xml to new xml doc instance.
XMLDocument backUp = new XMLDocument();
backUp.Save("Here file Path");
Jun 22, 2011 09:33 AM|narenderrawal007|LINK
I tried and have found the solution.I had been able to solve the issue like this
XmlNodeList NodeList = doc.GetElementsByTagName("Subroot");
for (int i = NodeList.Count - 1; i >= 0; i--)
XmlNode copyNode = docBackUp.ImportNode(NodeList[i], true);
But your solution is simple. Can't get much simpler ! Awesome. thanks.
Jun 23, 2011 03:40 AM|narenderrawal007|LINK
One thing I noticed is that My code append the records from main file to back up file due to appendchild method. But the outerxlml method will only copy the whole xml everytime and not append.