Im new to .net c# programming and i need to read remote xml file into dataset and create crystal report with the dataset.
我是.net c#编程的新手,我需要将远程xml文件读入数据集并使用数据集创建水晶报告。
so far everything works fine except some Unicode characters showing incorrectly in crystal report viewer
到目前为止一切正常,除了一些Unicode字符在水晶报表查看器中显示不正确
so is this the correct way to load xml file which contains unicode?
这是加载包含unicode的xml文件的正确方法吗?
string reportDataPath = "http://domain/test/data.xml";
DataSet reportData = new DataSet();
try
{
reportData.ReadXml(reportDataPath);
}
catch
{
}
to set source
设置来源
report = new SampleReport();
report.SetDataSource(reportData);
in xml file encoding set like
在xml文件中编码设置如
<?xml version="1.0" encoding="UTF-8"?>
edit:-
this is the problem im talking about. this is with sinhala unicode font
这是我在谈论的问题。这是与sinhala unicode字体
text in xml file is showing below
xml文件中的文本如下所示
crystal report viewer shows below text
水晶报告查看器显示在文本下面
Regards
1 个解决方案
#1
1
Typically I always try to be explicit with my encoding types so I would do it like this:
通常我总是试图明确我的编码类型,所以我会这样做:
System.Data.DataSet reportData = new System.Data.DataSet();
System.Net.WebRequest request= System.Net.WebRequest.Create(reportDataPath);
using (System.Net.WebResponse response = (System.Net.HttpWebResponse)request.GetResponse()) {
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
reportData.ReadXml(sr);
}
}
Just be aware that unicode can be encoded using different formats, UTF-8, UTF-16, etc. Mostly what you'll see is UTF-8. In .NET the encoding type Encoding.Unicode is UTF-16
请注意,unicode可以使用不同的格式编码,UTF-8,UTF-16等。您将看到的主要是UTF-8。在.NET中,编码类型Encoding.Unicode是UTF-16
#1
1
Typically I always try to be explicit with my encoding types so I would do it like this:
通常我总是试图明确我的编码类型,所以我会这样做:
System.Data.DataSet reportData = new System.Data.DataSet();
System.Net.WebRequest request= System.Net.WebRequest.Create(reportDataPath);
using (System.Net.WebResponse response = (System.Net.HttpWebResponse)request.GetResponse()) {
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
reportData.ReadXml(sr);
}
}
Just be aware that unicode can be encoded using different formats, UTF-8, UTF-16, etc. Mostly what you'll see is UTF-8. In .NET the encoding type Encoding.Unicode is UTF-16
请注意,unicode可以使用不同的格式编码,UTF-8,UTF-16等。您将看到的主要是UTF-8。在.NET中,编码类型Encoding.Unicode是UTF-16