XML中特殊字符转义
1 /// <summary> 2 /// 特殊字符转义 3 /// </summary> 4 /// <param name="xml"></param> 5 /// <returns></returns> 6 public string XmlCharacterEscaping(string xml) 7 { 8 string xmlNew = xml; 9 if (xml.IndexOf("&") != -1) 10 { 11 xmlNew = xml.Replace("&", "&"); 12 } 13 if (xml.IndexOf("<") != -1) 14 { 15 xmlNew = xml.Replace("<", "<"); 16 } 17 if (xml.IndexOf(">") != -1) 18 { 19 xmlNew = xml.Replace(">", ">"); 20 } 21 if (xml.IndexOf('"') != -1) 22 { 23 char c = '"'; 24 xmlNew = xml.Replace(c.ToString(), """); 25 }
26 return xmlNew; 27 }