XML转换成DataTable

        #region XML转dataset
        //str 是xml字符串
        public static DataTable GetResultXMLToDataTable    (string str,string Dt_Name)
        {
            DataSet xmlDs = new DataSet("ds");
            StringReader stream = null;
            XmlTextReader reader = null;
            try
            {
                using (stream = new StringReader(str))
                {
                    using (reader = new XmlTextReader(stream))
                    {
                        xmlDs.ReadXml(reader);
                        return xmlDs.Tables[Dt_Name];
                    }
                }
            }
            catch (Exception ex)
            {
               //Get Exception
            }
            finally
            {
                if (reader != null)
                    reader.Close();
                if (stream != null)
                    stream.Close();
            }
            return null;
        }

        #endregion

 

posted @ 2019-09-02 11:05  清风绿茶  阅读(789)  评论(0编辑  收藏  举报