C# XML转DataSet

1.主要实现代码如下:

PEISWS_Report_Print p1 = new PEISWS_Report_Print();  //webservice

string sGroupResult = p1.RequestExamReportList();   //调webservice返回xml文件

if (!string.IsNullOrEmpty(sGroupResult))
{
     DataTable dt = GetDataSetByXml(sGroupResult).Tables[0];  //XML转Datatable 实现方法GetDataSetByXml
}

        ///


        /// xml转dataset
        ///

        ///
        ///
        public static DataSet GetDataSetByXml(string xmlData)
        {
            StringReader stream = null;     //System.IO
            XmlTextReader reader = null;  //System.Xml
            try
            {
                DataSet xmlDS = new DataSet();
                stream = new StringReader(xmlData); //从stream装载到XmlTextReader               
                reader = new XmlTextReader(stream);
                xmlDS.ReadXml(reader);
                return xmlDS;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }    

2.sGroupResult内容大致为:

  

           体检号

 

      

          体检号

 

3. 返回DataSet如图片所示:

C# XML转DataSet_第1张图片

 

 

你可能感兴趣的:(C#)