Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode string to XML string in C#

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>
like image 411
user31673 Avatar asked Jul 20 '11 04:07

user31673


2 Answers

  1. HttpUtility.HtmlDecode from System.Web
  2. WebUtility.HtmlDecode from System.Net
like image 84
Kirill Polishchuk Avatar answered Nov 12 '22 10:11

Kirill Polishchuk


You can use System.Net.WebUtility.HtmlDecode instead of HttpUtility.HtmlDecode

Useful if you don't want System.Web reference and prefer System.Net instead.

like image 45
matabares Avatar answered Nov 12 '22 09:11

matabares