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("\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吧。

时间: 2024-07-29 17:28:28

DataSet 读取xml 报错有非法字符的相关文章

Python读取xml报错解析--ExpatError: not well-formed (invalid token)

xml文件内容如代码所示存入的名字为login.xml: <?xml version="1.0" encoding="utf-8"?> <info> <explain>126</explain> <url>http://www.126.com</url> <null username="" password="">请先输入您的邮箱帐号</

xml报错 Parse Fatal Error :在实体引用中,实体名称必须紧跟在&#39;&amp;&#39;后面

修改jndi配置文件中的密码后,重启tomcat报错如下  实际问题是xml中默认’&’是非法字符,用     &   替代 xml报错 Parse Fatal Error :在实体引用中,实体名称必须紧跟在'&'后面

pyquery 读取HTML报错UnicodeDecodeError: &#39;gbk&#39; codec can&#39;t decode byte 0xaf in position 78: illegal multibyte sequence

今天学习pyquery 读取HTML文件时,报错 这是字符编码错误,读取的时候不能读取gbk格式的字符 然后打开HTML文档,发现里面有中文字符,将中文字符去掉之后就可以执行了. pyquery 读取HTML报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 78: illegal multibyte sequence 原文地址:https://www.cnblogs.com/zll20153246/p/963

新建maven工程时pom.xml报错

新建maven工程时,pom.xml报错:第一行报如下错误:multiple annotations found at this line后添加org.eclipse.m2e相关的plugin配置后,错误消失,完整pom.xml如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schem

(转)解决dubbox-demo-provider.xml报错的问题:提示Failed to read schema document

背景:在eclipse项目中,经常会遇到xml文件提示找不到.xsd文件的情况.很有必要弄清xsd文件的加载过程! 1 解决过程 dubbo-demo-provider导入eclipse后dubbox-demo-provider.xml报错详情: Multiple annotations found at this line: - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be

android 程序中res/values-v14/styles.xml报错的解决办法

从旧的ADT迁移的新的ADT时, android 程序中res/values-v14/styles.xml报错: error: Error retrieving parent for item: No resource found that matches the given name :Theme.AppCompat.Light.DarkActionBar 解决办法:修改项目下的project-properties文件, 把下面这一行加入,指向新导入的support库(需要先导入这个库) an

保存xml报错 &#39;UTF_8&#39; is not a supported encoding name

ArgumentException: 'UTF_8' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. var doc=new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclarati

web.xml报错Cannot resolve class &#39;StrutsPrepareAndExecuteFilter&#39; (idea创建SSH项目)

原因: xwork-core.jar包已经合并到struts2-core.jar下,并且点开jar包,发现没有 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter查阅相关资料后得知:struts2 2.5之后,这个filter移动到了org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 这就是典型的过度依赖工具!写下此文告诫自己,

Python 读取csv报错编码问题 : UnicodeDecodeError: &#39;utf-8&#39; codec can&#39;t decode byte 0x87 in position 10: invalid start byte

1.报错信息 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 10: invalid start byte 2.解决方法 查找相关资料,发现一个棒棒的解决方法: 首先把csv文件以记事本的格式打开,默认保存是ANSI编码,我们应该手动修改成utf-8 ===>(如果记事本打开后是乱码,我们可以把csv数据粘贴到记事本上后保存) 3.接下来可以愉快的读文件咯 with csv23.open_csv(r'C:\