DataSet 读取xml 报错有非法字符

private void Bind()
        {
            string strLogPath = ConfigurationSettings.AppSettings["LOG_PATH"].ToString();
            if (strLogPath.Length > 0 && strLogPath[strLogPath.Length - 1] != '\')
                strLogPath += '\';

            string strXMLUrl = String.Format("{0}{1}.xml", strLogPath, DateTime.Now.ToString("yyyyMMdd"));

            string xmlContent = Common.Library.ReadFileAbsolute(strXMLUrl, ASCIIEncoding.GetEncoding("GB2312")).Replace("
", "");

            StringReader strReader = new StringReader(xmlContent);
            DataSet ds = new DataSet();
            ds.ReadXml(strReader);
            DataTable dt = ds.Tables["item"];
        }

ds.ReadXml(xmlContent);直接读取要报错 有非法字符

所以在read之前用流来读一次

StringReader strReader = new StringReader(xmlContent);

问题结局。原理自己google吧。

原文地址:https://www.cnblogs.com/huangyoum/p/4047709.html