C# 修改XML <DataSource> <Tables> <Number>1</Number> </Tables></DataSource>把里面1改成2 给出代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //linq to xml //SetAttributeValue() 给你个参考地址: 参考不要动不动就“给出代码” static void Main(string[] args) { XmlDocument mydoc = new XmlDocument(); mydoc.Load(@"D:\VS_Project\CSDNProject\CSDNConsole\bin\Debug\XMLFile1.xml"); XmlNode node = mydoc.SelectSingleNode("DataSource").ChildNodes[0].ChildNodes[0]; node.InnerText = "2";//修改内容 mydoc.Save(@"D:\VS_Project\CSDNProject\CSDNConsole\bin\Debug\XMLFile1.xml");//保存 } 一下代码仅供参考!修改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); } VS2005在生成软件包时,能不能调用指定的程序? 利用 新浪微博 提供的 api 编写一个 登陆?? Service Broker 求解 先谢谢 大家的帮助 c#很菜的问题 如何在web程序中实现选择一个文件夹,将其下的所有文件FTP批量上传 c# 中回调的一些问题 Syntax error in INSERT INTO statement. 有人用过Ndatabase对象数据库么,有点问题想咨询下 cs程序更新后无法运行 在C#中,如何开始一个程式?如: 在线等 C#中怎么调用RGB()方法 Drawstring怎样绘制斜放的字体 望高手不吝赐教
//linq to xml
//SetAttributeValue()
给你个参考地址: 参考
不要动不动就“给出代码”
static void Main(string[] args)
{
XmlDocument mydoc = new XmlDocument();
mydoc.Load(@"D:\VS_Project\CSDNProject\CSDNConsole\bin\Debug\XMLFile1.xml"); XmlNode node = mydoc.SelectSingleNode("DataSource").ChildNodes[0].ChildNodes[0];
node.InnerText = "2";//修改内容 mydoc.Save(@"D:\VS_Project\CSDNProject\CSDNConsole\bin\Debug\XMLFile1.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);
}