0

我想使用以下代码更新 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;
}

但它引发了 NotSupportedException 就行了node.SetValue( Version);,我不知道为什么,有什么想法可以解决这个问题

4

1 回答 1

1

XDocument 或 XElement 上的 XPathNavigator 是只读的,如果您想操作 XDocument 或 XElement,请使用 System.Xml.Linq 中公开的 API(例如http://msdn.microsoft.com/en-us/library/system .xml.linq.xelement.setvalue.aspx)。

于 2011-12-01T11:40:08.227 回答