Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <bookstore>
- <books>
- <author>
- </author>
- </books>
- </bookstore>
- <bookstore>
- <newnode>
- <books>
- <author>
- </author>
- </books>
- </newnode>
- </bookstore>
- XmlDocument doc = new XmlDocument();
- doc.Load("BookStore.xml");
- XmlElement newNode = doc.CreateElement("newnode");
- doc.DocumentElement.AppendChild(newNode);
- newNode.AppendChild(doc.SelectSingleNode("/bookstore/books"));
- doc.Save("BookStore.xml");
- XmlDocument xd = new XmlDocument();
- xd.Load("oldxmlfile.xml");
- XmlNode oldNode = xd["nameOfRootNode"];
- xd.RemoveAll();
- XmlNode newParent = xd.CreateNode("nodename");
- newParent.AppendChild(oldNode);
- xd.AppendChild(newParent);
- xd.Save("newXmlFile.xml");
- XmlDocument doc = new XmlDocument();
- // load the current xml
- doc.LoadXml(xml);
- // create a new "newnode" node and add it into the tree
- XmlElement newnode = (XmlElement) doc.DocumentElement.AppendChild(doc.CreateElement("newnode"));
- // locate the original "books" node and move it
- newnode.AppendChild(doc.SelectSingleNode("/bookstore/books"));
- // show the result
- Console.WriteLine(doc.OuterXml);
Add Comment
Please, Sign In to add comment