i have a project with xml,i must open a xml file in tree view,i've done this,but now
i want to add node.i have a existing file witch i've open,and in this xml file i need to insert new node,can someone help me with this.
thank you very much

9 Years
Discussion Span
Last Post by Jugortha

There are severals methods to add a node to your xml file including the use of the DOM(Document object models) methods so a propose this code I invite u to try it
suppose that we have an xml file

we want add
to the xml file
try to execute this method
public void Main()
XmlDocument doc = new XmlDocument();
doc.LoadXml("<books>" +
"<A>" +
"<B>book1</B>" +
"<C>book2</C>" +
"<D>book3</D>" +
"</A>" +

XmlNode root = doc.DocumentElement;

//Create  the E node.
XmlElement oNodeE = doc.CreateElement("E");
//Create the F node
XmlNode oNodeF = doc.CreateElement("F");
oNodeF.InnerText = "book4";
//Add the node to the document.
root.InsertAfter(oNodeE, root.SelectSingleNode("//book/A"));
//Save the file contents

There is not only this method of corse u can use other alternatives using xmlwriter, text writer
and within the .Net framework 3.5 there is xLing
library witch simplify a lot the achivement of such task

Edited by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.