【发布时间】:2014-05-20 07:26:55
【问题描述】:
我尝试了几种方法,但似乎都不起作用...
您可以通过查看注释的代码行来查看我尝试过的不同方法,但是我能够很好地获取属性,并且newIndex 已正确更新,但是当我去更改属性时调用 count 它什么也没做。
XmlElement reports = (XmlElement)doc.SelectSingleNode("//Reports");
XmlAttribute reportCount = (XmlAttribute)doc.SelectSingleNode("//Reports/@count");
int count = Convert.ToInt32(reportCount.Value);
newIndex = count + 1;
//doc.DocumentElement.SetAttribute("count", "\"" + newIndex.ToString() + "\"");
//reportCount.Value = newIndex.ToString();
reports.SetAttribute("count", newIndex.ToString());
XML 文件
<?xml version="1.0" encoding="utf-8"?>
<Reports count="1"><!--this count should be equal to the last id-->
<Report id="1">
<Workbook>APG0214.xlsx</Workbook>
<Filepath>\\fileserver\homeshares\POS Reports</Filepath>
</Report>
<Report id="2">
<Workbook>CBM0214.xlsx</Workbook>
<Filepath>\\fileserver\homeshares\POS Reports</Filepath>
</Report>
</Reports>
感谢任何帮助!
【问题讨论】:
-
你看过这篇文章了吗? stackoverflow.com/questions/367730/…