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 に答える