Xml encoding with StringBuilder : Xml Encoding « XML « C# / C Sharp






Xml encoding with StringBuilder

  


using System;
using System.Collections.Generic;
using System.Text;

public class EncodingUtil
{
    public static string XmlEncode(string value)
    {
        StringBuilder sb = new StringBuilder(value);
        sb.Replace("&", "&");
        sb.Replace("'", "'");
        sb.Replace("\"", """);
        sb.Replace(">", ">");
        sb.Replace("<", "&lt;");

        return sb.ToString();
    }
}

   
    
  








Related examples in the same category

1.Creates a XML encoding of the collection object and its current state with a given root name.