0

I have a XML string that contains these characters

&lt&#x3b;br /&gt&#x3b;
&lt&#x3b;br /&gt&#x3b;


How do I convert this into real HTML code like

<br /><br />

using asp.net C#

delphiman
  • 65
  • 2
  • 11
  • 2
    Possible duplicate of [Decoding all HTML Entities](https://stackoverflow.com/questions/8348879/decoding-all-html-entities) – aloisdg Aug 23 '18 at 16:36

3 Answers3

0

You could use Html.Decode in order to do so:

@Html.Decode("&amp;lt&#x3b;br &#x2f;&amp;gt&#x3b;&#xa;&amp;lt&#x3b;br &#x2f;&amp;gt&#x3b;&#xa;")
Haytam
  • 4,643
  • 2
  • 20
  • 43
0

You can utilize built in .NET utilites to decode the HTML characters such as ampersand (&).

See: HttpUtility.HtmlDecode and WebUtility.HtmlDecode (.NET 4.0+)

ShellNinja
  • 629
  • 8
  • 25
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("&lt;", "<")
          .Replace("&gt;", ">")
          .Replace("&quot;", "\"")
          .Replace("&apos;", "'")
          .Replace("&amp;", "&");
      return workingBuffer.ToString();
  }

Now, if the source is encoded HTML, then the other answers are correct.

Flydog57
  • 6,851
  • 2
  • 17
  • 18