处理WEB服务返回的XML数据的方法
//此方法是使用了XmlDataDocument
1 for (int i = 0; i < companyInfo.Tables[0].Rows.Count; i++) 2 { 3 string result = string.Empty; 4 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://c2.keyue.net/QPAPITRAN/CopInfo/Code/" + companyInfo.Tables[0].Rows[i]["海关编码"].ToString()); 5 request.Timeout = 10000; 6 request.AllowAutoRedirect = false; 7 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 8 if (response.StatusCode == HttpStatusCode.OK) 9 { 10 StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); 11 result = sr.ReadToEnd(); 12 sr.Close(); 13 } 14 15 16 if (result.Contains("CopName")) 17 { 18 19 XmlDataDocument xd = new XmlDataDocument(); 20 DataSet ds = new DataSet(); 21 xd.LoadXml(result); 22 ds.ReadXml(new XmlNodeReader(xd)); 23 24 if (ds != null && ds.Tables[0].Rows.Count > 0) 25 { 26 ExecuteSql(" update " + txtDBName.Text.Trim() + " set 企业名称 = '" + ds.Tables[0].Rows[0]["CopName"].ToString() + 27 "', 企业分级标志 = '" + ds.Tables[0].Rows[0]["CopType"].ToString() + 28 "', 有效日期 = '" + ds.Tables[0].Rows[0]["AvailDate"].ToString() + 29 "' where 海关编码='" + companyInfo.Tables[0].Rows[i]["海关编码"].ToString() + "'"); 30 } 31 32 } 33 34 35 }