Original empty tags are not preserved by HTMLAgilityPack.

asp.net c# html-agility-pack

Question

If i have some empty tags like this

<td  width="15px"/>

Agility pack fixes them to be like

<td  width="15px"></td>

Is anything possible to do to override this behavior ?

1
1
12/8/2010 4:13:07 PM

Accepted Answer

Try this before saving:

if (HtmlNode.ElementsFlags.ContainsKey("td"))
{
    HtmlNode.ElementsFlags["td"] = HtmlElementFlag.Empty | HtmlElementFlag.Closed;
}
else
{
    HtmlNode.ElementsFlags.Add("td", HtmlElementFlag.Empty | HtmlElementFlag.Closed);
}

This changes the behavior for all td elements which may not be what you want. I don't know of a way to accomplish this per-node.

1
12/8/2010 8:16:09 PM

Popular Answer

Set the OptionWriteEmptyNodes property to true on your HtmlDocument.



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