我想写一个xml文件,内容是这样
<xxxxxxx>
<asdf>
<aa>ttttttttttt</aa>
<bb>123</bb>
<cc>asdf</cc>
<dd>2008-1-25 8:27:29</dd>
<ee>0</ee>
</asdf>
<asdf>
<aa>dddddddddddddd</aa>
<bb>123</bb>
<cc>aaah</cc>
<dd>2008-1-25 8:28:29</dd>
<ee>0</ee>
</asdf>
<asdf>
<aa>bbbbbbbbbbbb</aa>
<bb>123</bb>
<cc>jjjj</cc>
<dd>2008-1-25 8:29:29</dd>
<ee>0</ee>
</asdf>
</xxxxxxx>
其中<ee>是读取过没有,0是没有读过,1是读过
有两个按钮,一个是读取,每读到一个就在textbox1里面写读到的内容
只输出没有读过的<asdf>
一个是停止,点了之后,可以停止读取程序关闭{
在程序关闭的时候还要更新一下xml文件,更新所有读取过的<asdf>,把<ee>从0变成1
再判断一下时间,如果到了中午12点,就自动把所有值为的1<ee>改回0
并且还要更新<cc>里的内容,调用update("<cc>内的内容")方法(这个我有)
}
<xxxxxxx>
<asdf>
<aa>ttttttttttt</aa>
<bb>123</bb>
<cc>asdf</cc>
<dd>2008-1-25 8:27:29</dd>
<ee>0</ee>
</asdf>
<asdf>
<aa>dddddddddddddd</aa>
<bb>123</bb>
<cc>aaah</cc>
<dd>2008-1-25 8:28:29</dd>
<ee>0</ee>
</asdf>
<asdf>
<aa>bbbbbbbbbbbb</aa>
<bb>123</bb>
<cc>jjjj</cc>
<dd>2008-1-25 8:29:29</dd>
<ee>0</ee>
</asdf>
</xxxxxxx>
其中<ee>是读取过没有,0是没有读过,1是读过
有两个按钮,一个是读取,每读到一个就在textbox1里面写读到的内容
只输出没有读过的<asdf>
一个是停止,点了之后,可以停止读取程序关闭{
在程序关闭的时候还要更新一下xml文件,更新所有读取过的<asdf>,把<ee>从0变成1
再判断一下时间,如果到了中午12点,就自动把所有值为的1<ee>改回0
并且还要更新<cc>里的内容,调用update("<cc>内的内容")方法(这个我有)
}
dataSet.ReadXml(XmlFilePath);
DataRow[] row = dataSet.Tables[0].Select(" ee='0' ");
*******,再操作这些Row即可
System.Xml.XmlDocument document = new System.Xml.XmlDocument();
document.Load(@"c:\\2.xml");
System.Xml.XmlNodeList nl = document.SelectNodes(@"//asdf[ee=0]");
foreach (System.Xml.XmlNode n in nl)
{
Console.WriteLine(n.InnerXml);
n.SelectSingleNode("ee").InnerText = "1";
n.SelectSingleNode("cc").InnerText= "update cc";
n.SelectSingleNode("dd").InnerText = DateTime.Now.ToString();
}
Console.WriteLine(document.InnerXml);
如果最多只有几十兆、不考虑效率的话,可以简单的写成如上形式
http://topic.csdn.net/u/20080227/14/8bce0844-bd15-42f0-9cda-a343d5d6601b.html?seed=2111206245
document.Load(@"c:\\2.xml");
System.Xml.XmlNodeList nl = document.SelectNodes(@"//asdf[ee=0]");
foreach (System.Xml.XmlNode n in nl)
{
Console.WriteLine(n.InnerXml);
n.SelectSingleNode("ee").InnerText = "1";
n.SelectSingleNode("cc").InnerText= "update cc";
n.SelectSingleNode("dd").InnerText = DateTime.Now.ToString();
}
Console.WriteLine(document.InnerXml); document.InnerXml再写文件就可以了啊
string bb=n.SelectSingleNode("bb").InnerText;
string cc=n.SelectSingleNode("cc").InnerText;这种需求你改改代码不就行了