C#—XML reading, adding, modifying and deleting operations
1.xml file format is as follows:
1. Read
DataSet ds = new DataSet();
ds.ReadXml (Server.MapPath(@"Projects.xml"));
DataTable dt = ds.Tables[0];
return dt;
//The obtained datatable is output in a loop in the foreground, omitting...
2. Added
XmlDocument xmlDoc = new ("project");
xe1.SetAttribute("name", txtProjectName.Text);
strVssPath = txtProjectVss.Text + "$" + txtProjectPath.Text + "$" + txtProjectSln.Text;
xe1.SetAttribute("vss -path",strVssPath);
root.AppendChild(xe1);
xmlDoc.Save(Path);
3. Modify
XmlDocument xmlDoc = new XmlDocument();
string Path = Server.MapPath(@"Projects.xml ");
XmlNodeList nodelist = xmlDoc.SelectSingleNode("projects").ChildNodes;
foreach (XmlNode xn in nodelist)
{
Getattribute ("name") == Request ["name"]. Tostring ()) {
xe.setattribute ("name", txtprojectName1.text); 1.Text + "$" + txtprojectpath1.text + "$" + txtProjectSln1.Text; XmlDocument();
string Path = Server.MapPath(@"Projects.xml");
xmlDoc.Load(Path);
XmlNodeList nodelist = xmlDoc.SelectSingleNode("projects").ChildNodes;
foreach (XmlNode xn in nodelist)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("name") == Request["name"].ToString())
{
xn.ParentNode.RemoveChild(xn);
xmlDoc.Save(Path);
}