
正文
DataSet 读取xml 报错有非法字符
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
private void Bind()
{
string strLogPath = ConfigurationSettings.AppSettings["LOG_PATH"].ToString();
if (strLogPath.Length > && strLogPath[strLogPath.Length - ] != '\\')
strLogPath += '\\'; string strXMLUrl = String.Format("{0}{1}.xml", strLogPath, DateTime.Now.ToString("yyyyMMdd")); string xmlContent = Common.Library.ReadFileAbsolute(strXMLUrl, ASCIIEncoding.GetEncoding("GB2312")).Replace("\r\n", ""); 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吧。








