代码如下:
StreamReader sr= new StreamReader(stream,System.Text.Encoding.GetEncoding("utf-8"));
try
{
xDoc.Load(sr);
}
catch(Exception ex)
{
sr= new StreamReader(stream,System.Text.Encoding.GetEncoding("gb2312"));
xDoc.Load(sr);
}
问题:
如果utf-8读不出来的话,后边的也读不出来,而如果先用gb2312读的话就可以读出来,感觉好像xDoc读过一次如果出错,后边就不会读成功。谁有类似的经验,请赐教。
StreamReader sr= new StreamReader(stream,System.Text.Encoding.GetEncoding("utf-8"));
try
{
xDoc.Load(sr);
}
catch(Exception ex)
{
sr= new StreamReader(stream,System.Text.Encoding.GetEncoding("gb2312"));
xDoc.Load(sr);
}
问题:
如果utf-8读不出来的话,后边的也读不出来,而如果先用gb2312读的话就可以读出来,感觉好像xDoc读过一次如果出错,后边就不会读成功。谁有类似的经验,请赐教。
解决方案 »
- Gridview的删除问题
- asp控件提问
- 要让Request.IsAuthenticated通过验证,在跳到此页的页面里面要怎么做(人代码怎么写才行)-很菜的问题-
- Datagrid的超连接HyperLinkColumn怎样传递两个参数到第二个页面?高手请指教。。。最后70分了
- 一个关于应用不同XSL命名空间的问题。
- 调查一下 大家用什么做网站
- Service Unavailable在nhibernate里如何处理?
- 请问各位.net前辈,.net的常用技术都有哪些?
- 怎么让alert中显示的内容换行??急,谢谢
- 我的asp.net为什么运行不了??????急!!!!!
- 请教一个关于.net2005下js的问题
- 求一正规表达式来验证是否为合法的Guid
如果不行
那就比较妖了
其实得到XML文件数据方法很多,比如XmlDocument doc = new XmlDocument();
doc.Load("StationList.xml");
XmlNodeList nodes = doc.SelectNodes(@"Stations/Station");
这是一种!DataSet ds = new DataSet();
string path = AppDomain.CurrentDomain.BaseDirectory + "ReportConfig.xml";
ds.ReadXml(path);
这是另一种方法!或者
using (StringReader sr = new StringReader(message))
{
dsData.ReadXml(sr);
}