XmlDocument类到二进制格式的转换 [英] XmlDocument class to binary format conversion

查看:350
本文介绍了XmlDocument类到二进制格式的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好社区

 我正在设计一个桌面应用程序,并重复使用以Xml文本格式存储其数据的代码.我使用System.Xml命名空间和XmlDocument,XmlAttributes来实现该目标.

  I'm designing a desktop app, and reusing code that stores it's data in Xml text format. I use the System.Xml namespace and the XmlDocument, XmlAttributes to achieve that goal.

 我想要转换XmlDocument对象并将其作为二进制文件保存到磁盘,然后从二进制文件加载它,因此它不再是人类可读的.我该怎么办?

  What I would like is to convert my XmlDocument object and save it to disk as a binary and load it from binary, so it's no longer human readable. How can I do this?

预先感谢.

推荐答案

为什么?仅仅获取文本并将其存储在二进制文件中绝不会使其变得不可读.任何二进制编辑器都可以并且将显示等效的文本,因此您一无所获.更糟糕的是,您将同时废除XML和二进制代码的好处. 二进制文件通常很小,读/写速度很快,并且布局方式很容易找到和加载信息,而无需加载整个文件. XML在许多方面是相反的.它更大,无需代码即可轻松操作,操作简便 阅读和验证.通过将它们组合在一起,您将同时具有两种缺点:-体积大,速度慢,不易读取和验证以及在不读取/写入整个文件的情况下无法更改.

Why? Simply taking text and storing it in a binary file in no way makes it unreadable.  Any binary editor can and will show the text equivalent so you gain nothing.  Even worse is that you're nullifying the benefit of both XML and binary.  Binary files tend to be small, fast to read/write and laid out in such a way that it is easy to find and load information without loading the entire file.  XML is, in many regards, opposite.  It is larger, easier to manipulate without code and easy to read and verify.  By combining them together you get all the disadvantages of both, namely - large, slow, not easy to read and verify and not changeable without reading/writing the entire file.

我个人将以您最经常需要的数据格式存储数据.如果确实需要其他格式,则将数据序列化为特定于格式的布局.

Personally I would store the data in whatever format you most often need the data in.  In the cases where you do need the alternative format then serialize the data to the format specific layout.

迈克尔·泰勒
http://blogs.msmvps.com/p3net

Michael Taylor
http://blogs.msmvps.com/p3net


这篇关于XmlDocument类到二进制格式的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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