I have an xml file where I need "&" to be printed for a checkbox name in a form. But the "&" is not printed. The notation I have used is &
. But in this case it is not printed. How can I do this, Is there any other way to represent? The XML format is mentioned below.
<?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>
The code snippet is below,
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;
}
In the form,
public void FillUICaption(ref Language currentLanguage)
{
chkbox.Text = language.TXT_DEFAULT_KET;
}
The code to access the value,
public string TXT_DEFAULT_KET{ get { return GetString("1000"); } }