首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XpathNavigator提升错误NotSupportedException

XpathNavigator提升错误NotSupportedException
EN

Stack Overflow用户
提问于 2011-12-01 19:15:18
回答 1查看 211关注 0票数 0

我想使用以下代码更新XDocument

代码语言:javascript
复制
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,我不知道为什么,有什么想法可以解决这个问题吗

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-01 19:40:08

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8340436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档