Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Streamreader data to XmlDocument?

In C#, I am trying to get call a webservice which returns an XML file.

I can make a HttpWebRequest to the webservice and store the output in a StreamReader. But how can I convert this data into an XMLDocument?

like image 705
Troyes22 Avatar asked Sep 01 '25 10:09

Troyes22


1 Answers

Use XmlDocument.Load() - I'm using the overload that accepts an XmlReader to cash in on XmlReader.Create's auto-encoding detection:

XmlDocument document = new XmlDocument();
using(Stream stream = request.GetResponse().GetResponseStream()) {        
    using(XmlReader reader = XmlReader.Create(stream)) {
        document.Load(stream);
    }
}
like image 145
Jeff Sternal Avatar answered Sep 03 '25 18:09

Jeff Sternal