异常:"根级别上的数据无效。 第 1 行,位置 1。"
使用 XmlDocument.Load(path); 方法来读取一个encoding为utf-16的xml时,就报了以上异常。
Xml文件:
<?xml version="1.0" encoding="utf-16"?>
<DataProviders>
<Provider
Name="A"
Type="OleDataProvider"
ConnectionString="Provider=SQLOLEDB.1;Password=xx;User ID=sa;Data Source=192.168.1.x\SQL2008;Initial Catalog=xxx" />
<Provider
Name="B"
Type="SubSonic.SqlDataProvider, SubSonic"
ConnectionString="Password=xx;Persist Security Info=True;User ID=sa;Database=xx;Data Source=192.168.1.x\SQL2008" />
</DataProviders>
在网上找了一下都不知道怎么解决。经过摸索以及Msdn上的启发,得出以下解决方案:
1. 将 uft-16 修改成 utf-8。
这是最简单的方式,