protected void butAdd_Click(object sender, EventArgs e) { try { XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml")); xmlDoc.Element("Persons").Add(new XElement("Person", new XElement("Name", txtName.Text), new XElement("City", txtCity.Text), new XElement("Age", txtAge.Text))); xmlDoc.Save(Server.MapPath("People.xml")); jsCall("Data successfully added to XML file."); readXML(); } catch { jsCall("Sorry, unable to process request. Please try again."); } }
People.xml
Persons
if (xmlDoc.Element("Persons") == null) { then create that node and add it to the document; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)