SharePoint Tips

Thursday, November 16, 2017

Format XML - C#, Replace Special Characters from XML File

public class FormatXML
    {
        /// <summary>
        /// Read the xml file to string
        /// </summary>
        /// <param name="fileName">full file path</param>
        /// <returns></returns>
        public string ReadXmlFile(string fileName)
        {
            string xmlString = System.IO.File.ReadAllText(fileName);
            return xmlString;
        }

/// <summary>
        /// Replace special characters from xml file
        /// </summary>
        /// <param name="fileName">full file path</param>
        /// <returns></returns>
        public string ReplaceSpecialChar(string fileName)
        {
            string xmlString = ReadXmlFile(fileName);
            xmlString = xmlString.Replace("&lt;", "<").Replace("&gt;", ">");
            return xmlString;
        }
    }

No comments:

Post a Comment