How to decode string to XML string in C#

user31673 picture user31673 · Jul 20, 2011 · Viewed 68.1k times · Source

I have a string (from a CDATA element) that contains description of XML. I need to decode this string into a new string that displays the characters correctly using C#

Existing String:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><myreport xmlns="http://test.com/rules/client"><admin><ordernumber>123</ordernumber><state>NY</state></report></myreport>

String Wanted:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myreport xmlns="http://test.com/rules/client">
<admin><ordernumber>123</ordernumber><state>NY</state></report></myreport>

Answer

Kirill Polishchuk picture Kirill Polishchuk · Jul 20, 2011
  1. HttpUtility.HtmlDecode from System.Web
  2. WebUtility.HtmlDecode from System.Net