FOLLOW US
softpcapps Software CODE HELP BLOG



Freeware Open Source Windows Software Applications and Free Online Tools

For Windows 11 : Download and run .NET 3.5 Installer if the application is not running

How to XML Encode a String

To XML encode a string do the following :

 
		string text_to_encode="this is < a test > !";
		
		XmlDocument xmlDoc = new XmlDocument();

        XmlElement xmlElement = xmlDoc.CreateElement("Str");

        xmlElement.InnerText = text_to_encode;

        string xml_encoded_text= xmlElement.InnerXml;

Please note that you have to also add "using System.XML;" on the top.

Download Demo Project

Encode Decode Demo Project