Loading HTML string using HTMLAgilityPack

c# html-agility-pack

Question

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.

Accepted Answer

Issue resolved after adding

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



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why