开发者

System.NotSupportedException XDocument.Save

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 L开发者_如何学JAVAoadXmlFile()
{
  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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜