检查未开封的标签一个HTML字符串 [英] Checking a HTML string for unopened tags

查看:119
本文介绍了检查未开封的标签一个HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串作为HTML源,我想检查是否HTML源代码是字符串中包含这是不打开的标签。

I have a string as a HTML source and I want to check whether the HTML source which is string contains a tag which is not opened.

例如字符串下面包含< / U> 波形没有开通后< U>

For example the string below contains </u> after WAVEFORM which has no opening <u>.

WAVEFORM</u> YES, <u>NEGATIVE AUSCULTATION OF EPIGASTRUM</u> YES,

我只是想检查这些类型的未开封的标签,然后我不得不打开标签附加到字符串的开始?

I just want to check for these types of unopened tag and then I have to append the open tag to the start of the string?

推荐答案

有关,您可以使用 HTML敏捷性包这种特定情况下断言如果HTML结构良好,或者如果你有标签不开了。

For this specific case you can use HTML Agility Pack to assert if the HTML is well formed or if you have tags not opened.

var htmlDoc = new HtmlDocument();

htmlDoc.LoadHtml(
    "WAVEFORM</u> YES, <u>NEGATIVE AUSCULTATION OF EPIGASTRUM</u> YES,");

foreach (var error in htmlDoc.ParseErrors)
{
    // Prints: TagNotOpened
    Console.WriteLine(error.Code);
    // Prints: Start tag <u> was not found
    Console.WriteLine(error.Reason); 
}

这篇关于检查未开封的标签一个HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆