//删除
private int DelNode(string sValue)//sValue为专业名称,比如计算机专业,通信专业等。
{
string filePath=Server.MapPath("../appCode/xml文件名称.xml");
XmlDocument xmld = new XmlDocument();
try
{
xmld.Load(filePath);
XmlNode xmlParent=xmld.DocumentElement.SelectSingleNode("//xml文件名称/school/tsinghua");//删除清华里面的专业,可以把tsinghua改成其他节点的值
XmlNodeList xmlList=xmld.SelectNodes("//xml文件名称/school/tsinghua/flag");
foreach (XmlNode xmlDel in xmlList)
{
if(xmlDel.InnerText==sValue)
{
xmlParent.RemoveChild(xmlDel);
}
}
if(xmlList!=null)
{
xmld.Save(filePath);
return 0;
}
else
{
return -1;
}
}
catch(Exception exp)
{
return -1;
}
}
修改:
string filePath=Server.MapPath("../appCode/xml文件名称.xml");
XmlDocument xmld = new XmlDocument();
xmld.Load(filePath);
XmlNode element=xmld.DocumentElement.SelectSingleNode("//xml文件名称/school/tsinghua");
element.Attributes["caption"].Value=txtName.Text.Trim();
element.Attributes["score"].Value=txtPrice.Text.Trim();
xmld.Save(filePath);
没有评论:
发表评论