views:

362

answers:

3

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.

A: 

As you can read on the website

There is also no adherence to XHTML

Mork0075
Although the is no adherence to XHTML, I am entering the / but it is stripping it out. Is there a way to not do this, or override it?
mickyjtwin
+1  A: 

There is an option to turn on XML output that makes this issue go away.

var htmlDoc = new HtmlDocument();
htmlDoc.OptionOutputAsXml = true;
htmlDoc.LoadHtml(rawHtml);
Geoff
one problem with this method is that previously encoded entities, like a non braking space, gets encoded, this may be unwanted behaviour
MJJames
+2  A: 

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

doc.OptionWriteEmptyNodes = true;
Rahul