我有以下代码,它的最后一行在每次执行时都会产生一个NotSupportedException,但我还没有找到解决它的方法。这个假设的类似代码查找具有特定标题的“书”,目标是将其更新为新标题。它确实找到了正确的节点,但无法更新它。
XPathDocument xpathDoc = new XPathDocument( fileName );
XPathNavigator nav = xpathDoc.CreateNavigator();
XPathNavigator node = nav.SelectSingleNode( @"//Book[Title='OldTitle']/Title" );
node.SetValue( "NewTitle" );任何帮助都将不胜感激。
发布于 2009-10-21 23:55:07
由XPathDocument对象创建的XPathNavigator对象是只读的(请参见MSDN: Remarks)
它应该是用XmlDocument创建的,以便可以编辑:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
XPathNavigator nav = xmlDoc.CreateNavigator();
XPathNavigator node = nav.SelectSingleNode(@"//Book[Title='OldTitle']/Title");
node.SetValue("NewTitle");https://stackoverflow.com/questions/1601769
复制相似问题