Silverlight XML Save 不会覆盖整个文件 [英] Silverlight XML Save does not overwrite the entire file

查看:45
本文介绍了Silverlight XML Save 不会覆盖整个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解释我的问题的最好方法是举例.

The best way to explain my problem is by a example.

我有一个 Xml 文件,其中包含一些元素.当我删除一个元素时,我再次保存文件并出现此问题:

I have a Xml file with some elements in it. When I remove a element, I save the file again and this problem occurs:

保存前

    <?xml version="1.0" encoding="utf-8"?>
<ElementTree>
  <Elements1 />
  <Elements2>
    <Element Name="TestElement" ID="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
  </Elements2>
  <Elements3 />
</ElementTree>

保存后

<?xml version="1.0" encoding="utf-8"?>
<ElementTree>
  <Elements1 />
  <Elements2 />
  <Elements3 />
</ElementTree>D="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
  </Elements2>
  <Elements3 />
</ElementTree>

我怀疑它在做什么:它一直在写入文本,直到到达要保存的文本的末尾,然后停止.它不会删除在流中的最后一个字符之后仍写入文件中的文本.

What I suspect it is doing: It keeps writing the text untill it has reached the end of the text to be saved and then it stops. It does not remove the text that is still writen in the file AFTER the last character in the stream.

我该如何解决这个问题?

How can I fix this?

推荐答案

确保您打开时替换现有文件,然后正确关闭流.

Make sure you replace the existing file when opening it and you close the stream correctly.

这篇关于Silverlight XML Save 不会覆盖整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆