如何将XML中某个节点的值读取出来,将其数值+1再保存到该节点呢?请提供实例代码。一旦解决立即给分!
解决方案 »
- 谁用过sever.execute这个方法,帮忙讲解一下。
- 通过email发送激活地址的方式找回密码,激活地址应该点设计
- 有些网站的在线视频,在播放前或者播放后会播放自己的广告,这是怎么加的?
- 倾家荡产了~~~~最后的 一点点分也散了~~~~~~~~~~~~~ 有关 web自定义控件的问题
- DataGrid 选中行变颜色问题
- 如何实现把XML的内容加载到控件树Tree上,最好有代码,谢谢!
- Textbox获得焦点的属性 是不是onClick
- 保持session
- 急!!!关于DropDownList数据绑定的问题!!!
- DataAdapter中的tableMapping其什么作用?讨论
- 急!!!请教一个页面存在多个用户控件的数据验证问题?
- 我保存到数据库里是文件上传的路径!怎样把文件读出来!
doc.Load(@"e:\test.xml");int i=int.Parse(doc.DocumentElement.ChildNodes[0].InnerText)+1;
doc.DocumentElement.ChildNodes[0].InnerText=i.ToString();doc.Save(@"e:\test.xml");------------------------
测试XML:
<?xml version="1.0" encoding="gb2312"?>
<Article>
<BookName>11111</BookName>
</Article>结果XML:
<?xml version="1.0" encoding="gb2312"?>
<Article>
<BookName>11112</BookName>
</Article>
xmlDocument.LoadXml("c:\stat.xml");
int iValue = Convert.ToInt32(xmlDocument.SelectSingleNode("//click").InnerText);
xmlDocument.SelectSingleNode("//click").InnerText = iValue + 1;
xmlDocument.Save("c:\stat.xml");
先谢谢2位,我研究研究!
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(folder.ToString() + "/" + maxID + ".xml"), System.IO.FileMode.Create);
System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(fs, null);
tw.Formatting = System.Xml.Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("talk");
//tw.WriteStartElement("reply");
["name"].ToString());
tw.WriteElementString("content", txtContent.Text);
tw.WriteElementString("title", txtTitle.Text);
tw.WriteElementString("case", txtCase.Text);
tw.WriteElementString("source", txtSource.Text);
tw.WriteElementString("address", txtAddress.Text);
tw.WriteElementString("date", txtDate.Text);
tw.WriteElementString("click", "0");
这样的话,我怎么样在doc.Load(@"e:\test.xml");里写出我确切要的那个xml呢?谢谢谢谢
ID.InnerText = maxID.ToString();
我觉得已经很接近答案了……再拉兄弟一把呀!
刚才你给的代码,我指定某XML文件的话已经成了!谢谢先,但是因为我在后台每次发布都产生一个XML文件,根据我的ID节点,每次+1来生成。代码就是上面那段。我再贴我的XML文件:
<?xml version="1.0"?>
<talk>
<content>5</content>
<title>2222222222222222</title>
<case>222222222222222</case>
<source>222</source>
<address />
<date />
<click>0</click>
</talk>
doc.Load(@"e:\test.xml");int i=int.Parse(doc.DocumentElement.LastChild.InnerText)+1; //最后一个节点的值+1
doc.DocumentElement.LastChild.InnerText=i.ToString();doc.Save(@"e:\test.xml");
doc.Load(@"e:\folder.ToString() + "/" + maxID + ".xml"");我可以这样写吗?
xmlDocument.Load(@"c:\stat.xml");
int iValue = Convert.ToInt32(xmlDocument.SelectSingleNode("talk/click").InnerText);
xmlDocument.SelectSingleNode("talk/click").InnerText = iValue + 1;
xmlDocument.Save(@"c:\stat.xml");
XmlDocument doc = new XmlDocument();
string t1 = "../admin/data/BasketballHistory.xml";
doc.Load(Server.MapPath(t1));//打开文件
System.Xml.XmlNodeList nodeList = doc.GetElementsByTagName("ID");
int id = (Int32.Parse(nodeList[nodeList.Count - 1].InnerText) );
System.Text.StringBuilder maxID = new System.Text.StringBuilder(id.ToString());
string sFile = "e:/SlamDunkChinesePortal/sdsite/admin/data" + "/" + maxID + "/"+maxID+".xml";
doc.Load(sFile);
int i = int.Parse(doc.DocumentElement.ChildNodes[0].InnerText) + 1;
doc.DocumentElement.ChildNodes[0].InnerText = i.ToString();
doc.Save(sFile);
可是为什么不管我刷新哪个,都只有最后那个XML文件的click值+1呢?
int id = (Int32.Parse(nodeList[nodeList.Count - 1].InnerText) );这句代码是取最后一个的ID的值吗?
这个是/admin/data/BasketballHistory.xml的内容:
<?xml version="1.0" encoding="utf-8"?>
<list>
<theme>
<title>篮球运动传入中国</title>
<ID>101</ID>
<sort>0</sort>
<date>2004-10-14</date>
</theme>
<theme>
<title>使球从篮筐里落下来竟花了22个春秋</title>
<ID>102</ID>
<sort>0</sort>
<date>2004-10-14</date>
</theme>
<theme>
<title>篮球历史</title>
<ID>103</ID>
<sort>0</sort>
<date>2004-10-14</date>
</theme>
<theme>
<title>你好</title>
<ID>104</ID>
<sort>0</sort>
<date>2004-10-20</date>
</theme>
<theme>
<title>你好</title>
<ID>105</ID>
<sort>0</sort>
<date>2004-10-20</date>
</theme>
</list>
int id = (Int32.Parse(nodeList[nodeList.Count - 1].InnerText) );这里得到的ID应该是105
http://community.csdn.net/Expert/topic/3475/3475913.xml?temp=.9036676