c# streamReader转XmlDocument读取节点
http获得web(url)请求,先是获得数据流streamreader,之后将String数据流转换为xmldocument,之后xmlnode读取节点。
// get the response WebResponse webResponse = webRequest.GetResponse(); if (webResponse == null) { return null; } //需要将返回的编码进行指定,指定成默认的即可 StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.UTF8); string streamString = sr.ReadToEnd().Trim().Replace("\n", "");//去掉换行符 XmlDocument doc = new XmlDocument(); doc.LoadXml(streamString);//加载文档 XmlNode test1 = doc.SelectSingleNode("returnsms");//根节点 string aaa = test1.SelectSingleNode("returnstatus").InnerText;//子节点