System.NotSupportedException XDocument.Save

发布于 2024-11-27 13:10:50 字数 771 浏览 2 评论 0原文

我的 Silverlight 应用程序中有一个 XML 文件,其中包含应用程序设置并将在运行时进行编辑。到目前为止,我已经能够很好地反序列化到应用程序中,但无法保存对 XDocument 所做的任何更改。这是我正在使用的代码。

private XElement _targetRoot;
private XDocument _doc;
private Stream _stream;

private void LoadXmlFile()
{
  WebClient xmlClient = new WebClient();
  xmlClient.OpenReadCompleted += XMLFileLoaded;
  xmlClient.OpenReadAsync(new Uri(_fileName, UriKind.Relative));
}

private void XMLFileLoaded(object sender, OpenReadCompletedEventArgs e)
{
  if (e.Error != null)
  {
    return;
  }
    _stream = e.Result;
    _doc = XDocument.Load(_stream);
    deserializeScenarioList(_doc.Root.Element("scenes"));
}

然后,每当我尝试从节点中删除元素然后通过保存时,

_doc.save(_stream) 

我都会收到 System.NotSupportedException。

I have an XML file within a Silverlight application that contains application settings and will be edited during runtime. So far I have been able to deserialize into the application fine, but cannot save any changes I make to the XDocument. Here's the code I'm using.

private XElement _targetRoot;
private XDocument _doc;
private Stream _stream;

private void LoadXmlFile()
{
  WebClient xmlClient = new WebClient();
  xmlClient.OpenReadCompleted += XMLFileLoaded;
  xmlClient.OpenReadAsync(new Uri(_fileName, UriKind.Relative));
}

private void XMLFileLoaded(object sender, OpenReadCompletedEventArgs e)
{
  if (e.Error != null)
  {
    return;
  }
    _stream = e.Result;
    _doc = XDocument.Load(_stream);
    deserializeScenarioList(_doc.Root.Element("scenes"));
}

Then any time I try to remove elements off a node and then save via

_doc.save(_stream) 

I get a System.NotSupportedException.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2024-12-04 13:10:50

流是一种单向流,在本例中是从服务器到 (Silverlight) 客户端的流。

为了将更改保存回服务器,Web 应用程序必须公开一个端点,Silverlight 控件可以调用该端点将文件传回。一种简单的方法是向 Web 应用程序添加 ASMX Web 服务(WCF 端点和 REST 端点当然也是可能的)。

A stream is a one-way only stream, in this case a stream from the server to the (Silverlight) client.

In order to save the changes back to the server, the web application will have to expose an endpoint which the Silverlight control can call to transfer the file back. An easy way to do this if to add an ASMX web service to the web application (WCF endpoint and REST endpoints are of course also possible).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文