I am calling a third party service and they send the response as Xml. However, as I am using WebClient to call the service the response I get is a byte array.
var client = new WebClient();
var result = client.UploadValues(post_url, data);
result is a byte array. How do I convert it to XML to read the response given by the third party service?
You can turn the bytes into a string:
string xml = Encoding.UTF8.GetString(result);
and then parse it :
XDocument doc = XDocument.Parse(xml);
Use a MemoryStream
:
using (var stream = new MemoryStream(result))
{
var doc = XDocument.Load(stream);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With