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 ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Set the OptionWriteEmptyNodes property to true on your HtmlDocument.
Method 2
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.
Method 3
While @Corbin March’s answer doesn’t work as desired, it’s the only one I’ve found that comes close. The problem is that HAP still does some additional fixup that makes this a problem.
From the original code:
<td width="15px"/>
By set the ElementFlags as above the closing element tag indeed is not created, however the original trailing “/” is removed. This could be a problem depending on your scenario, it was for me. The original fragment becomes:
<td width="15px">
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0