C#从字节数组创建XML [英] c# create xml from byte array

查看:122
本文介绍了C#从字节数组创建XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有xml字节数组,从中获取xml字符串的最佳方法是什么?我试图使用xmltextreader和memorystream,但是没有成功.

i have xml what i get as byte array, whats the best way to get the xml string out of it? I was tryng to use xmltextreader and memorystream but with no success..

推荐答案

XmlDocument doc = new XmlDocument();
string xml = Encoding.UTF8.GetString(buffer);
doc.LoadXml(xml);

OR

XmlDocument doc = new XmlDocument();
MemoryStream ms = new MemoryStream(buffer);
doc.Load(ms);

这假定您的数据具有UTF8编码,这对于XML是常见的.另外buffer这是字节数组.

This assumes your data has UTF8 encoding which is the usual for XML. Also buffer here is the byte array.

这篇关于C#从字节数组创建XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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