修改XML文件里节点中的内容:
XmlDocument xmlDoc = new XmlDocument();
string path = Server.MapPath("~/xml/shopCityXml/2shopCity.xml");
if (System.IO.File.Exists(path) == true)
{
xmlDoc.Load(path);
XmlNodeList nodeList = xmlDoc.SelectSingleNode("adXMLPath").ChildNodes;//获取bookstore节点的所有子节点
string ID = "";
string type = "";
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
if (xn.Name == "adItem")
{
XmlElement xe = (XmlElement)xn;
XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode xn1 in nls)//遍历
{
XmlElement xe2 = (XmlElement)xn1;//转换类型
if (xe2.Name == "ID")
{
ID = xe2.InnerText.ToString();
}
if (xe2.Name == "type")
{
type = xe2.InnerText.ToString();
}
if (ID == "1" && type == "slide")
{
if (xe2.Name == "title")
{
xe2.InnerText = "";
xe2.AppendChild(xmlDoc.CreateCDataSection(txtSuperMarketTitle.Text.ToString().Trim()));
}
if (xe2.Name == "url")
{
xe2.InnerText = "";
xe2.AppendChild(xmlDoc.CreateCDataSection(txtSuperMarketLinkUrl.Text.ToString().Trim()));
}
if (xe2.Name == "imgUrl")
{
xe2.InnerText = "";
if (upLoad1.M_upLoadError == "succes")
{
xe2.AppendChild(xmlDoc.CreateCDataSection(upLoad1.M_upLoadUrlAddress));
if (upLoad1.M_oldUrlAddress != "" && upLoad1.M_oldUrlAddress != "../testImages/IM.jpg")
{
string ImageUrl = Server.MapPath(upLoad1.M_oldUrlAddress);
File.Delete(ImageUrl);
}
}
else
{
xe2.AppendChild(xmlDoc.CreateCDataSection(upLoad1.M_oldUrlAddress));
}
}
if (xe2.Name == "directions")
{
xe2.InnerText = "";
xe2.AppendChild(xmlDoc.CreateCDataSection(txtDescription.Text.ToString().Trim()));
break;
}
}
}
}
}
FileInfo fi = new FileInfo(path);
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
fi.Attributes = FileAttributes.Normal;
}
xmlDoc.Save(path);
}