1

I am loading HTML passed as string into HTMLAgilityPack document as below.

 HtmlDocument html = new HtmlDocument();
 html.OptionOutputAsXml = true;
 html.LoadHtml(htmlText);
 HtmlNode document = html.DocumentNode;

After loading the document.InnerHtml shows up with &quot(sample below) for all the quotes.How can I avoid this?

<span style=\"\\&quot;MARGIN-LEFT:\" class=\"\\&quot;form_title\\&quot;\" _20px5c_22_=\"\">MyText</span>

I would want the sample to be displayed as below.

<span class=\"form_title\" style=\"MARGIN-LEFT: 20px\">MyText</span>

From the obtained "document" I have to loop and find elements(using fizzler component). But with "&quot" appearing I am not able to do so.

6
  • 3
    What is the original HTML like?
    – Oded
    Feb 19, 2013 at 16:01
  • As @Oded said: What is the original HTML page you're trying to parse? You could try using HttpUtility.HtmlDecode(document.InnerHtml) method on System.Web assembly. Feb 20, 2013 at 1:07
  • HTML is complex. It's of a dynamic page with many hidden controls. If i copy it to text file it's about 150kb. I don't see a way to attach it here.
    – San
    Feb 20, 2013 at 3:56
  • @San - What about the relevant part - say the span you have shown as an example - can you post the actual source as seen on a browser?
    – Oded
    Feb 20, 2013 at 8:32
  • 1
    @san - please answer yourself so the question is marked as answer Feb 20, 2013 at 12:56

1 Answer 1

4

Issue resolved after adding

HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form"); 
HtmlDocument html = new HtmlDocument();
html.OptionAutoCloseOnEnd = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.