I have a XML string that contains these characters
<br />
<br />

How do I convert this into real HTML code like
<br /><br />
using asp.net C#
I have a XML string that contains these characters
&lt;br /&gt;
&lt;br /&gt;

How do I convert this into real HTML code like
<br /><br />
using asp.net C#
You could use Html.Decode
in order to do so:
@Html.Decode("&lt;br /&gt;
&lt;br /&gt;
")
You can utilize built in .NET utilites to decode the HTML characters such as ampersand (&).
See: HttpUtility.HtmlDecode and WebUtility.HtmlDecode (.NET 4.0+)
It's worth noting that the encoding rules for XML differ from those of HTML (there are only 5 characters that need encoding in XML). This function is useful for encoding XML:
System.Security.SecurityElement.Escape(unencodedString);
I use this for decoding encoded XML (note that the ampersand is last in the list):
public static string XmlDecode(string encodedString)
{
var workingBuffer = new StringBuilder(encodedString);
workingBuffer.Replace("<", "<")
.Replace(">", ">")
.Replace(""", "\"")
.Replace("'", "'")
.Replace("&", "&");
return workingBuffer.ToString();
}
Now, if the source is encoded HTML, then the other answers are correct.