早上以前都正常,弄的时候SelectSingleNode还能找到数据
下午怎么就不行了,反复调试的时候观察到:
root正常。
bookroot不正常,只返回第一条。参数bname输入正常。
nodels正常。这里也用到了bname,都能找到数据。
public static void removebookmark(string bname,string mark)
{
string file = "d:\\book.xml";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(file);
XmlNode root = xmldoc.SelectSingleNode("books");
XmlNode bookroot = xmldoc.SelectSingleNode("books/book['" + bname + "']");
if (mark == name)
{
bookroot.RemoveAll();
root.RemoveChild(bookroot);
}
else
{
XmlNodeList nodels = xmldoc.SelectNodes("books/book['" + bname + "']/mark");
foreach (XmlNode nd in nodels)
{
if (nd.InnerText == mark)
{
bookroot.RemoveChild(nd);
}
}
}
xmldoc.Save(file);
}
<?xml version="1.0" encoding="utf-8"?>
<books>
<book bname="687" url="C:\Documents and Settings\Administrator\桌面\687.txt">
<mark>1</mark>
<mark>3</mark>
</book>
<book bname="1321622" url="C:\Documents and Settings\Administrator\桌面\1321622.txt">
<mark>11</mark>
<mark>31</mark>
</book>
</books>
动漫人物
智慧大石