XpathNavigator引发错误NotSupportedException
我想使用以下代码更新XDocumentXpathNavigator引发错误NotSupportedException,xpath,c#-3.0,xpathnavigator,Xpath,C# 3.0,Xpathnavigator,我想使用以下代码更新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
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(版本)行上引发NotSupportedException
,我不知道为什么,有什么办法可以解决这个问题,XDocument或XElement上的XPathNavigator是只读的,如果您想操作XDocument或XElement,那么就使用System.Xml.Linq中公开的API(例如)。什么是版本?它的定义是什么?