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

巴扎黑
Release: 2016-12-20 13:29:02
Original
1102 people have browsed it

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

}




Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template