我想使用以下代码更新XDocument
private static bool ResetUpdateVersion()
{
// this indicate either the verwsion is different or not
// this will either call the update only or writting the defualt
bool Result = false;
//// check for version using xpath
XPathNavigator navigator = document.CreateNavigator();
//ShortcutList is the main element that contain all the other elements
XPathNavigator node = navigator.SelectSingleNode(@"/ShortcutList");
XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);
if (node != null)
{
if (node.GetAttribute("Version", ns.DefaultNamespace) != Version)
{
node = navigator.SelectSingleNode(@"/ShortcutList/@Version");
node.SetValue( Version);
Result = true;
}
else
{
Result = false;
}
}
return Result;
}但是它在线路node.SetValue( Version);上引发了NotSupportedException,我不知道为什么,有什么想法可以解决这个问题吗
发布于 2011-12-01 19:40:08
XDocument或XElement上的XPathNavigator是只读的,如果您想操作XDocument或XElement,请使用System.Xml.Linq中公开的API(如http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.setvalue.aspx)。
https://stackoverflow.com/questions/8340436
复制相似问题