Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top