Create a detailed guide on how to perform create, read, update, delete operations on XML file in ASP.NET Web Form.
Loading
Create a detailed guide on how to perform create, read, update, delete operations on XML file in ASP.NET Web Form.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Cynthia SathuragiriPosted Mar 24, 2026, 4:24 AM
In ASP.NET Web Forms, you can perform CRUD operations on an XML file using the
XmlDocumentclass.1. Create (Insert)
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/products.xml"));
XmlElement product = doc.CreateElement("Product");
product.SetAttribute("id", "2");
XmlElement name = doc.CreateElement("Name");
name.InnerText = "Mobile";
product.AppendChild(name);
doc.DocumentElement.AppendChild(product);
doc.Save(Server.MapPath("~/App_Data/products.xml"));
```
2. Read
XmlNodeList list = doc.SelectNodes("/Products/Product");
foreach (XmlNode node in list)
{
string name = node["Name"].InnerText;
}
```
3. Update
XmlNode node = doc.SelectSingleNode("/Products/Product[@id='1']");
node["Name"].InnerText = "Updated Name";
doc.Save(path);
```
4. Delete
XmlNode node = doc.SelectSingleNode("/Products/Product[@id='1']");
node.ParentNode.RemoveChild(node);
doc.Save(path);
```
Use XPath to locate nodes and always save changes using
doc.Save(). XML is suitable for small data storage; for larger apps, prefer a database.