/// 读取多语言的资源文件
/// </summary>
/// <param name=”frmName”>窗体的Name</param>
/// <param name=”lang”>要显示的语言(如ZH或EN)</param>
/// <returns></returns>
public static Hashtable ReadResource(string frmName,string lang){
Hashtable result = new Hashtable();
XmlReader reader = null;
FileInfo fi = new FileInfo(“resources/AppResource_” + lang + “.xml”);
if (!fi.Exists)
reader = new XmlTextReader(“resources/AppResource.xml”);
else
reader = new XmlTextReader(“resources/AppResource_” + lang + “.xml”);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
XmlNode root = doc.DocumentElement;
XmlNodeList nodelist = root.SelectNodes(“Form[Name=”” + frmName + “”]/Controls/Control”);
foreach (XmlNode node in nodelist){
try{
XmlNode node1 = node.SelectSingleNode(“@name”);
XmlNode node2 = node.SelectSingleNode(“@text”);
if (node1 != null){
result.Add(node1.InnerText.ToLower(),node2.InnerText);
}
}catch(FormatException fe){
Console.WriteLine(fe.ToString());
}
}
reader.Close();
return result;
}
运行时候报错
本人的resources中有AppResource_EN.xml和AppResource_ZH.xml,但是没有resources/AppResource.xml
程序跳入这里后
reader中为None.
求高手解惑,还有resources/AppResource.xml代表什么意思
80