HTMLAgilityPack 不保留原始的空标签
如果我有一些像这个敏捷包这样的空标签,
<td width="15px"/>
请将它们修复为类似
<td width="15px"></td>
是否可以做任何事情来覆盖此行为?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
HtmlDocument
上的OptionWriteEmptyNodes
属性设置为 true。Set the
OptionWriteEmptyNodes
property to true on yourHtmlDocument
.保存之前尝试此操作:
这会更改所有 td 元素的行为,这可能不是您想要的。我不知道有什么方法可以完成每个节点的任务。
Try this before saving:
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.虽然@Corbin March 的答案没有达到预期效果,但这是我发现的唯一一个接近的答案。问题是 HAP 仍然做了一些额外的修复,这使得这个问题成为一个问题。
从原始代码来看:
通过如上所述设置 ElementFlags,确实不会创建结束元素标记,但是原始的尾随“/”被删除。根据您的情况,这可能是一个问题,这对我来说是。原始片段变为:
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:
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: