Html Agility Pack unclosed embed, param tags

.net asp.net c# html-agility-pack

Question

A try to parse embed-object tag like this:

HtmlNode source2 = HD.CreateElement("source"); source2.InnerHtml =

<object width="640" height="390" ><param name="movie" value="http://videa.hu/flvplayer.swf?v=SMxjdkVDqmrfAxJz" /><param name="allowscriptaccess" value="always" /><param name="allowFullScreen" value="true" /><embed width="640" height="390" src="http://videa.hu/flvplayer.swf?v=SMxjdkVDqmrfAxJz" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" /></object><br /><a href="http://videa.hu/videok/jarmuvek/markoloval-tisztitjak-a-parkolot-az-SMxjdkVDqmrfAxJz"> title="fdsdf sdf">dsdfs fs dfsd fsd </a>n here.

The problem is when I try the document code HD.DocumentNode.OuterHtml or source2.InnerHtml the param and embed tag will be unclosed.

I tried

HtmlNode.ElementsFlags["param"] = HtmlElementFlag.Closed;

but get an extra close tag.

thanks

Popular Answer

Try this,

 HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
 document.LoadHtml(loadhtmlstring);
 document.OptionFixNestedTags = true;

When you load the html in to the HtmlDocument try to fix the html tags. then you can solve you problem. that is allow to automatically fix the tag errors of the HTML.




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