AppendChild 和指定方法不支持异常
下面的代码给出了此错误消息“不支持指定的方法”。但是 这里是相同的示例和我的。
FileInfo file = new FileInfo("../../file.xml");
XDocument xfile = XDocument.Load(file.FullName);
XPathNavigator nav = xfile.CreateNavigator();
nav.AppendChild("<pages>100</pages>");
Below code gives this error message "Specified method is not supported". But here is sample which is same with mine.
FileInfo file = new FileInfo("../../file.xml");
XDocument xfile = XDocument.Load(file.FullName);
XPathNavigator nav = xfile.CreateNavigator();
nav.AppendChild("<pages>100</pages>");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您从 XML 源对象创建
XPathNavigator
时,导航器最终回调原始对象以读取其数据并进行更改。您提供的代码示例与您链接到的代码示例不同,因为它们是从可读写的XmlDocument
创建XPathNavigator
。您正在从只读的XDocument
创建一个文档。每种类型的 XML 对象都会返回其自己的
XPathNavigator
版本,该版本受到其来源对象的功能的限制。When you create an
XPathNavigator
from an XML source object, the navigator ultimately calls back into the original object to read its data and make its changes. The code sample you provided is not the same as the one you link to, because they are creating theXPathNavigator
from anXmlDocument
, which is read-write. You are creating one from anXDocument
, which is read-only.Each type of XML object returns its own version of an
XPathNavigator
, which is limited by the capabilities of the object it came from.