C# Xml Manipulation: Copy Node
Just loop through your xml structure using xPath, create a new node object, set the innertext property to value of the node to copy and then insert the value at the end of the current node set.
XmlDocument xdocLocalFile = new XmlDocument(); xdocLocalFile.Load("MyXmlFile.xml"); foreach (XmlNode xNodeCopy in xdocLocalFile.SelectNodes("/root/phunk")) { XmlNode xNodeNew = xdocLocalFile.CreateNode(XmlNodeType.Element, "NewNodeName", null); xNodeNew.InnerText = xNodeCopy.SelectSingleNode("CurrentNodeName").FirstChild.Value; xNodeCopy.InsertAfter(xNodeNew, xNodeCopy.LastChild); }
