Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From byte[] to XmlTextReader

Tags:

c#

my question is pretty simple, I've an array of bytes (fullfilled via Sockets) and I would like transform it into a XmlTextReader object. How can I do this?

This doesn't work :

byte[] buffer = new byte[5000]; // TODO a revoir
int sizeReceived;

sizeReceived = _socket.Receive(buffer);
string s = Encoding.UTF8.GetString(buffer, 0, sizeReceived); // s is correctly fulfilled with XML a get back
MemoryStream memory = new MemoryStream(buffer);
memory.Position = 0;

return new XmlTextReader(memory);

Thanks for help.

like image 836
Arnaud F. Avatar asked Dec 07 '10 13:12

Arnaud F.


1 Answers

Set start and end index of stream.

byte[] buffer = new byte[5000]; // TODO a revoir
int sizeReceived;

sizeReceived = _socket.Receive(buffer);
MemoryStream memory = new MemoryStream(buffer, 0, sizeReceived);
return new XmlTextReader(memory);
like image 71
Jonas Elfström Avatar answered Nov 09 '22 02:11

Jonas Elfström