XmlDocument.WriteTo截断结果文件 [英] XmlDocument.WriteTo truncates resultant file

查看:68
本文介绍了XmlDocument.WriteTo截断结果文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将XmlDocument序列化为文件.XmlDocument很大.但是,在调试器中,我可以看到InnerXml属性中包含所有XML Blob-在那里没有被截断.

Trying to serialize an XmlDocument to file. The XmlDocument is rather large; however, in the debugger I can see that the InnerXml property has all of the XML blob in it -- it's not truncated there.

以下是将XmlDocument对象写入文件的代码:

Here's the code that writes my XmlDocument object to file:

// Write that string to a file.
var fileStream = new FileStream("AdditionalData.xml", FileMode.OpenOrCreate, FileAccess.Write);
xmlDocument.WriteTo(new XmlTextWriter(fileStream, Encoding.UTF8) {Formatting = Formatting.Indented});
fileStream.Close();

此处生成的文件只写到第5760行,实际上是在标签中间被截断了!

The file that's produced here only writes out to line like 5,760 -- it's actually truncated in the middle of a tag!

任何人都知道为什么会在这里截断吗?

Anyone have any ideas why this would truncate here?

更新:我找到了问题的根源.关闭文件流之前,我没有关闭XML Text Writer!哦!

Update: I found the source of the issue. I was not closing the XML Text Writer before closing the file stream! D'oh!

推荐答案

XmlTextWriter未正确关闭.哇!

The XmlTextWriter wasn't closed properly. Woops!

这篇关于XmlDocument.WriteTo截断结果文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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