开发者

How to convert Streamreader data to XmlDocument?

开发者 https://www.devze.com 2023-01-27 00:38 出处:网络
In C#, I am trying to g开发者_高级运维et 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

In C#, I am trying to g开发者_高级运维et 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?


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


Use System.Xml.Linq.XDocument.Load(streamreader);


You should store the received output in a StringWriter or just a stringand the load it using XmlDocument.Load(string).

0

精彩评论

暂无评论...
验证码 换一张
取 消