HtmlAgilityPack LoadHtml - Issue with empty P tags

c# html-agility-pack

Question

I'm attempting to load basic HTML.

var html = "<div>something<p></p></div>";

var doc = new HtmlDocument();
doc.LoadHtml(html);

after this HTML has loadeddoc.InnerHtml produces this:

<div>something<p></div>

As a result, the ending P tag is lost, and my HTML is screwed up.

Can somebody assist me with this? I can't seem to locate a solution.

1
3
5/25/2017 3:11:45 PM

Accepted Answer

You're searching for the OptionWriteEmptyNodes flag:

Defines if empty nodes must be written as closed during output.

In your situation:

doc.OptionWriteEmptyNodes = true;

Yields:

<div>something<p /></div>
1
5/25/2017 8:56:03 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow