tags:

views:

290

answers:

2

Hi everybody!

This situation is driving me crazy!!: the following snippet does not work (as i should)

...
string preResult =  doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText
return HttpUtility.HtmlDecode(preResult);
...

The first line assigns a value (e.g.) "<b> Dummy value: </ b> into preResult (that's expected).

BUT the next line gives AGAIN the same value!!! But it should return "<b> Dummy value: </ b>".

Debugging these lines i thought to copy and paste the value directly into HttpUtility.HtmlDecode() and guess what...it worked!!! I got the expected value!

Of course this is useless, but it proves something weird is going on...what?!!

Has anybody faced the same situation again? (dev.env. VS2008,.NET3.5SP1)

Thanks in advance

A: 

If the values are stored in the XML file as &lt;b&gt; Dummy value: &lt;/ b&gt; then getting the InnerText will automatically HtmlDecode the text. There's no need to call HtmlDecode.

Robaticus
That's what i thought either! But i guess we 're not right! The InnerText returns exactly this string and nothing else!
Savvas Sopiadis
I ran this with that code within an XML node, retrieved it using InnerText and did a Debug.Writeline of the text, and it showed up well formed. Are you trying to put it on a web page?
Robaticus
A: 

Use InnerHtml instead of InnerText.

This worked for me:

aDiv.InnerHtml = HttpUtility.HtmlDecode(aString);

I am using this to display the formatted text on a web page.

absynce