Reputation: 14309
So, I've got a SMS service posting data to an ASP page.
The data is coming in as HTML encoded xml. It looks like this when I read it from the InputStream directly:
Content-Disposition: form-data; name="xml"
<POSTBACK>
<NOTIFICATION id="4254" created="2012-07-02 13:35:46.629214-04">
<ORIGIN>SMS_MO</ORIGIN>
<CODE>N211</CODE>
<BODY><FROM>+15035555555</FROM><TO>60856</TO><TEXT>cats are cats</TEXT><RECEIVED>2012-07-02 13:35:46.038477-04</RECEIVED></BODY>
</NOTIFICATION>
</POSTBACK>
------------------------------fde0d0d3bf3c--
I know I can manually go in and replace the character codes and then read it into an XmlDoc... which is what I am doing for time's sake.
What I'm wondering is if there is a native data type or built-in class to handle XML form data?
Tried:
string cleanString = HttpUtility.HtmlDecode(strRawtext);
but it looks the same for some reason.
Upvotes: 1
Views: 699
Reputation: 23123
HttpUtility.HtmlDecode Method should be able to handle this.
This worked fine for me:
private static void HtmlDecodeTest()
{
string html = @"
<POSTBACK>
<NOTIFICATION id=""4254"" created=""2012-07-02 13:35:46.629214-04"">
<ORIGIN>SMS_MO</ORIGIN>
<CODE>N211</CODE>
<BODY><FROM>+15035555555</FROM><TO>60856</TO><TEXT>cats are cats</TEXT><RECEIVED>2012-07-02 13:35:46.038477-04</RECEIVED></BODY>
</NOTIFICATION>
</POSTBACK>";
string x = HttpUtility.HtmlDecode(html);
Console.WriteLine(x);
}
Results:
<POSTBACK>
<NOTIFICATION id="4254" created="2012-07-02 13:35:46.629214-04">
<ORIGIN>SMS_MO</ORIGIN>
<CODE>N211</CODE>
<BODY><FROM>+15035555555</FROM><TO>60856</TO><TEXT>cats are cats</TE
XT><RECEIVED>2012-07-02 13:35:46.038477-04</RECEIVED></BODY>
</NOTIFICATION>
</POSTBACK>
Upvotes: 1