Alex Rivera | Logout

c# create xml from byte array

Asked 2011-04-07T13:47:49.577
31

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

Edit
Report

1 Answer

7

Assuming your xml is in the default 'UTF8' encoding., you could do something like this;

string xml = System.Text.UTF8Encoding.UTF8.GetString(bytes);
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument().LoadXml(xml);

Or this;

XmlDocument doc = new XmlDocument();
using (MemoryStream ms = new MemoryStream(buffer))
{
    doc.Load(ms);
}
answered 2011-04-07T13:55:41.893

Your Answer