小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

ASP.NET XML讀取、增加、修改和刪除操作

 昵稱10504424 2013-02-19

C#—XML讀取、增加、修改和刪除操作
1.xml文件格式如下:
<?xml version="1.0" encoding="utf-8"?>
<projects>
<project name="PlatformFramewo" vss-path="Platform$/Source CodHdt$Pla~1.sln" />
</projects>

1.讀取
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"Projects.xml"));
DataTable dt = ds.Tables[0];
return dt;
//得到的datable在前臺進行循環(huán)輸出,省略...
<tr style="font-weight: bold;"> //文字加粗
<td style="border-bottom: solid 2px gray;"> //文字底部加橫線

2.新增
XmlDocument xmlDoc = new XmlDocument();
string Path = Server.MapPath(@"Projects.xml");
xmlDoc.Load(Path);
XmlNode root=xmlDoc.SelectSingleNode("projects");
XmlElement xe1 = xmlDoc.CreateElement("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.修改
XmlDocument xmlDoc = new 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())
     {
         xe.SetAttribute("name", txtProjectName1.Text);
         strVssPath = txtProjectVss1.Text + "$" + txtProjectPath1.Text + "$" + txtProjectSln1.Text;
         xe.SetAttribute("vss-path", strVssPath);
         xmlDoc.Save(Path);
      }
   }

4.刪除
XmlDocument xmlDoc = new 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);
   }
}

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多