Home >Backend Development >C#.Net Tutorial >ASP.NET XML reading, adding, modifying and deleting operations

ASP.NET XML reading, adding, modifying and deleting operations

巴扎黑
巴扎黑Original
2016-12-20 13:29:021137browse

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...
//Make the text bold
//Add a horizontal line at the bottom of the text

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 ");

xmlDoc.Load(Path);

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);
}

}




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn