如何一个XmlDocument转换为数组<字节>?数组、转换为、字节、XmlDocument

2023-09-03 10:15:31 作者:討人歡喜

我构建了一个的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文档的文本编码,那么默认编码切换到所需的编码,或按照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.