Image tag not closing with HTMLAgilityPack

html-agility-pack

Question

Using the HTMLAgilityPack to write out a new image node, it seems to remove the closing tag of an image, e.g. should be but when you check outer html, has .

string strIMG = "<img src='" + imgPath + "' height='" + pubImg.Height + "px' width='" + pubImg.Width + "px' />";

HtmlNode newNode = HtmlNode.Create(strIMG);

This breaks xhtml.

Popular Answer

Telling it to output XML as Micky suggests works, but if you have other reasons not to want XML, try this:

doc.OptionWriteEmptyNodes = 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