【发布时间】:2014-08-07 05:44:12
【问题描述】:
我有一个 xml 文件,我需要在其中为表单中的复选框名称打印“&”。但是没有打印“&”。我使用的符号是&。但在这种情况下,它不会被打印出来。我该怎么做,有没有其他的方式来表示? XML 格式如下所述。
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE Strings[<!ELEMENT Strings ANY><!ELEMENT String ANY><!ATTLIST String Name ID #REQUIRED>]> <Strings> <String Name="0">&</String> </Strings>
下面是sn-p的代码,
public string Load(string _strShortName)
{
StreamReader reader = null;
string l_strShortname = _strShortName;
try
{
xmlCurrentLanguage = new XmlDocument();
//added for the fix and commented
if (File.Exists(strPath + "lang_" + _strShortName + ".xml"))
{
reader = new StreamReader(File.OpenRead(strPath + "lang_" + _strShortName + ".xml"));
}
else
{
//hot fix language change issue.
reader =new StreamReader(File.OpenRead( strPath + "lang_en.xml"));
}
xmlCurrentLanguage.PreserveWhitespace = true;
xmlCurrentLanguage.Load(reader);
reader.Close();
reader.Dispose();
}
catch (Exception e)
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
MessageBox.Show(e.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
return l_strShortname;
}
public string GetString(string _id)
{
// Versuche eine zu laden
XmlNode node = null;
if (xmlCurrentLanguage != null)
{
node = xmlCurrentLanguage.GetElementById(_id);
if (node != null)
{
return Parse(node.InnerText);
}
}
return "";
}
private string Parse(string str)
{
string parsedStr;
parsedStr = str.Replace("\n", System.Environment.NewLine);
parsedStr = str.Replace("%n", System.Environment.NewLine);
return parsedStr;
}
public string GetText(string _id, params string[] _cmd)
{
string str = GetString(_id);
string origError = GetString(_id + "_O");
if (origError != "")
{
for (int i = 0; i < _cmd.Length; i++)
{
str = _cmd[i].Replace(origError, str);
}
}
else
{
for (int i = 0; i < _cmd.Length; i++)
{
str.Replace("%" + (i + 1), _cmd[i]);
}
}
return str;
}
在表格中,
public void FillUICaption(ref Language currentLanguage)
{
chkbox.Text = language.TXT_DEFAULT_KET;
}
访问值的代码,
public string TXT_DEFAULT_KET{ get { return GetString("1000"); } }
【问题讨论】: