AppendChild from XmlNode class. Here is a short example to
use InsertAfter().
http://weblogs.asp.net/sonukapoor/articles/132854.aspx
Sonu Kapoor
Blog: http://weblogs.asp.net/sonukapoor/
-----Original Message-----
(Type your message here)
--------------------------------
From: Lalit Dubey
Hi I use the following code to append an file and read the same but it is overwriting in the file without
appending it ::
// this was to creat the xml file and append it Sring XmlFile="Data.xml;
System.IO.DirectoryInfo directoryInfo;
System.IO.DirectoryInfo directoryXML;
directoryInfo = System.IO.Directory.GetParent (Application.StartupPath);
if (directoryInfo.Name.ToString() == "bin")
{
directoryXML = System.IO.Directory.GetParent (directoryInfo.FullName);XmlFile = directoryXML.FullName + "\\" + "Data.xml";
}
else
{
XmlFile = directoryInfo.FullName + "\\" + "Data.xml"}
XmlTextWriter XmlWtr = new System.Xml.XmlTextWriter (XmlFile,null);
XmlWtr.Formatting=Formatting.Indented;
XmlWtr.WriteStartDocument();
XmlWtr.WriteStartElement("emplyees");
XmlWtr.WriteStartElement("emplyee");
XmlWtr.WriteElementString("empID", empid.Text);
XmlWtr.WriteElementString("name", empname.Text);
XmlWtr.WriteElementString("age", empage.Text);
XmlWtr.WriteElementString("level", level.SelectedItem.ToString());XmlWtr.WriteElementString("salary", empsalary.Text);
XmlWtr.WriteEndElement();
XmlWtr.WriteStartElement("emplyee");
XmlWtr.WriteElementString("empID", "35");
XmlWtr.WriteElementString("name", "kumar");
XmlWtr.WriteElementString("age", "34");
XmlWtr.WriteElementString("level", "Leader");
XmlWtr.WriteElementString("salary", "220000");
XmlWtr.WriteEndElement();
XmlWtr.WriteEndElement();
XmlWtr.WriteEndDocument();
XmlWtr.Flush();
XmlWtr.Close();
it is over-writing the file again and and again
////then i write to read it
textBox1.visible=true
XmlTextReader XmlRdr = new System.Xml.XmlTextReader (XmlFile);while(XmlRdr.Read())
{
if(Rdr.NodeType==XmlNodeType.Element&&XmlRdr.Name =="name")
{
textbox1.text= XmlRdr.ReadString() + "\r\n";
}
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>E+Ak789Z4Em5+Ofwc2J7tg==</Id>
.