【问题标题】:XpathNavigator raise error NotSupportedExceptionXpathNavigator 引发错误 NotSupportedException
【发布时间】:2011-12-01 11:15:17
【问题描述】:

我想使用以下代码更新 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,我不知道为什么,有什么办法解决这个问题

【问题讨论】:

  • 什么是版本?它是在哪里定义的?

标签: xpath c#-3.0 xpathnavigator


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    相关资源
    最近更新 更多