1

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

this doesn't seem to produce results when doing string decoded = HttpUtility.HtmlDecode(strRawtext); hmm.
Err. Yeah so my "log" for tracking the results was XML itself, so when I inserted it as InnerText for testing, it converted everything back into html encoding. dur. so now i'm appending the real nodes and it's good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.