Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert url-like string to xml string in C#?

I am sending xml/mathml as data in my AJAX request, and at the server side in C# I get this sort of text:

%3Cmath%3E%0A%20%20%20%20%3Cmrow%3E%0A%20%20%20%20%20%20%20%20%3Cmsub%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cmi%3Ex%3C%2Fmi%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cmtext%3E12%3C%2Fmtext%3E%0A%20%20%20%20%20%20%20%20%3C%2Fmsub%3E%0A%20%20%20%20%20%20%20%20

So, basically it is xml, but the xml basic characters are converted to url like characters, %20, %3E, %0A etc...

I have this POST method in my API controller:

[HttpPost]
public HttpResponseMessage PostUpload(HttpRequestMessage req)
{
    string jsonContent = req.Content.ReadAsStringAsync().Result;
    Utility.Utility.WriteLineToConsole("json data post: " + jsonContent);

    return Request.CreateResponse(HttpStatusCode.OK, jsonContent);
} 

The Utility function WriteLineToConsole() prints the jsonContent and the top text among the result.

How can i covert the string above to xml, i.e replace the url-like characters to xml characters?

Note: I am using MVC 4 / C# , jQuery AJAX, and both contentType and dataType are of type json. I want my data object to be like

data:{mathml: "<math>...</math>"}
like image 493
Vlad Avatar asked Dec 12 '25 04:12

Vlad


1 Answers

HttpUtility.UrlDecode(thatString)

did the job

like image 177
Vlad Avatar answered Dec 13 '25 16:12

Vlad