Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# create xml from byte array

Tags:

c#

xml

bytearray

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..

like image 923
hs2d Avatar asked Apr 07 '11 13:04

hs2d


1 Answers

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); 

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

like image 142
Aliostad Avatar answered Oct 02 '22 00:10

Aliostad