XML中特殊字符转义

 /// <summary>
/// 特殊字符转义
/// </summary>
/// <param name="xml"></param>
/// <returns></returns>
public string XmlCharacterEscaping(string xml)
{
string xmlNew = xml;
if (xml.IndexOf("&") != -)
{
xmlNew = xml.Replace("&", "&amp;");
}
if (xml.IndexOf("<") != -)
{
xmlNew = xml.Replace("<", "&lt;");
}
if (xml.IndexOf(">") != -)
{
xmlNew = xml.Replace(">", "&gt;");
}
if (xml.IndexOf('"') != -)
{
char c = '"';
xmlNew = xml.Replace(c.ToString(), "&quot;");
}
return xmlNew;
}
上一篇:《1Q84》--[日]村上春树


下一篇:C#扫描仪编程、条形码识别编程资料