我想使用以下代码更新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,我不知道为什么,任何解决这个问题的想法
答案 0 :(得分:1)
XDocument或XElement上的XPathNavigator是readonly,如果你想操作XDocument或XElement,那么使用System.Xml.Linq中公开的API(例如http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.setvalue.aspx)。