CSharp examples for System.Xml:XML Document
Escapes the specified text (or string version of an object) and returns a string safe to embed with an Xml document.
using System.Xml.Xsl; using System.Xml; using System.Text.RegularExpressions; using System.Text; using System;// w w w . j av a 2 s. c o m public class Main{ #region Escape(); Unescape(); /// <summary> /// Escapes the specified text (or string version of an object) and returns a string safe to embed with an Xml document. /// </summary> /// <param name="Text">The text to be escaped</param> /// <returns>The escaped string version of the text</returns> public static string Escape(object Text) { string sText = Parser.ToString(Text); if(sText != null && sText.Length > 0) { //escape: & (ampersand) sText = sText.Replace("&", "&"); //escape: <> (less than/greater than) sText = sText.Replace("<", "<").Replace(">", ">"); //escape: "' (quote/apostrophe) sText = sText.Replace("\"", """).Replace("'", "'"); } return sText; } }