[英]How can i find extra closing div in html string
I have some html stored in database .我有一些 html 存储在数据库中。 I dont know that html stored in databse has extra closing div like
</div>
or not.我不知道存储在数据库中的 html 是否有像
</div>
这样的额外关闭div 。 I want to find extra closing div in html string.我想在 html 字符串中找到额外的关闭 div。 I have tried to find using HTML Agility pack but not find the way to achieve this.
我试图找到使用HTML 敏捷包但没有找到实现此目的的方法。 Example:
例子:
<div class="readers">
A total of 218 users are reading this article.
</div>
</div>
</div>
How can i find these two extra closing div and extract fully valid html.我怎样才能找到这两个额外的关闭div并提取完全有效的 html。
Use this pure javascript parser before rendering the html: http://ejohn.org/blog/pure-javascript-html-parser/在呈现 html 之前使用此纯 javascript 解析器:http: //ejohn.org/blog/pure-javascript-html-parser/
You can check out by pasting your code here, http://ejohn.org/apps/htmlparser/ it removes the extra </div>
s.您可以通过在此处粘贴您的代码来查看, http ://ejohn.org/apps/htmlparser/ 它会删除多余的
</div>
。
You just need to pass your html to the HTMLtoXML
function as:您只需要将 html 传递给
HTMLtoXML
函数,如下所示:
HTMLtoXML(your_html);
and it would remove the extra closing tags.并且它会删除额外的结束标签。 Infact what it does is that it converts it into xml format, but since you are dealing with html strigs & all tags are expected to be valid in html, you can be safe to use this.
事实上,它所做的是将其转换为 xml 格式,但由于您正在处理 html strigs 并且所有标签都应该在 html 中有效,因此您可以安全地使用它。
EDIT: You can easily call javascript functions from a C# file.编辑:您可以轻松地从 C# 文件调用 javascript 函数。 See this question for more details.
有关详细信息,请参阅此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.