softpcapps Software CODE HELP BLOG

Shareware and free Open Source Windows Software Applications and free Online Tools

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