如何一个XmlDocument转换为数组<字节>? [英] How to convert an XmlDocument to an array<byte>?

查看:154
本文介绍了如何一个XmlDocument转换为数组<字节>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个的XmlDocument ,现在我想将它转换为数组。如何才能做到这一点?

I constructed an XmlDocument and now I want to convert it to an array. How can this be done?

谢谢

推荐答案

请尝试以下操作:

using System.Text;
using System.Xml;

XmlDocument dom = GetDocument()
byte[] bytes = Encoding.Default.GetBytes(dom.OuterXml);

如果你想preserve文档的文本编码,那么默认编码切换到所需的编码,或按照<一href="http://stackoverflow.com/questions/1500259/how-to-convert-an-xmldocument-to-an-arraybyte/1500269#1500269">Jon飞碟双向的建​​议。

If you want to preserve the text encoding of the document, then change the Default encoding to the desired encoding, or follow Jon Skeet's suggestion.

这篇关于如何一个XmlDocument转换为数组&LT;字节&GT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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