views:

50

answers:

1

i am using the HTML Agility pack to convert

 <font size="1">This is a test</font>

to

 This is a test

using this code:

 HtmlDocument doc = new HtmlDocument();
 doc.LoadHtml(html);
 string stripped = doc.DocumentNode.InnerText;

but i ran into an issue where i have this:

 <font size="1">This is a test &amp; this is a joke</font>

and the code above converted this to

This is a test &amp; this is a joke

but i wanted it to convert it to:

This is a test & this is a joke

does the html agility pack support what i am trying to do? why doesn't the HTML agiligy code do this by default or i am doing something wrong ?

+2  A: 

You can run HttpUtility.HtmlDecode() on the output.

However, note that InnerText will include HTML tags that may be contained inside the outermost tag. If you want to remove all tags, you will have to walk the document tree and retrieve all the text bit by bit.

Timwi
ooo
HttpUtility.HtmlDecode(" ") gives me a space as expected.
Mikael Svenson
@ooo — It is unclear why you thought it wouldn’t work for  , but it does...
Timwi