FOLLOW US
4dots Software CODE BLOG

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
 

Please Donate!

Please Share!