如何修复HTML标签(这是缺少的<&开放GT;&安培;<关闭>标签)与HTMLAgilityPack [英] How to fix html tags(which is missing the <open> & <close> tags) with HTMLAgilityPack
问题描述
我有℃的HTML; DIV>< H1>你好你好< / DIV> < DIV>喜< / P>< / DIV>
所需的输出:< DIV> < H1>你好< / H1>< / DIV> < DIV>< P>喜< / P>< / DIV>
使用HTML敏捷包是可以修复这种类似的问题,缺少的关闭和开启的标签?
Using HTML agility pack is it possible to fix this kind of similar issues with missing closing and opening tags?
推荐答案
该库是不是足够的智能来创建开放 p
,你把它,但它是足够的智能来创建缺少的 H1
。 。而在一般情况下,它会创建有效的HTML一如既往,但并不总是一个你所期望的。
The library isn't intelligent enough to create the opening p
where you put it, but it's intelligent enough to create the missing h1
. And in general, it creates valid HTML always, but not always the one you would expect.
所以这个代码:
HtmlDocument doc = new HtmlDocument();
doc.Load(yourhtml);
doc.Save(Console.Out);
将倾的:
will dump this:
<div><h1> hello Hi</h1></div> <div>hi <p></div>
这是不是你想要的,但有效的HTML。
你还可以添加一个小窍门是这样的:
Which is not what you want, but is valid HTML. You can also add a little trick like this:
HtmlNode.ElementsFlags["p"] = HtmlElementFlag.Closed;
HtmlDocument doc = new HtmlDocument();
doc.Load(yourhtml);
doc.Save(Console.Out);
这将转储这样的:
<div><h1> hello Hi</h1></div> <div>hi <p></p></div>
这篇关于如何修复HTML标签(这是缺少的<&开放GT;&安培;<关闭>标签)与HTMLAgilityPack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!