Fix missing HTML Tags using htmlagility pack

html html-agility-pack

Question

I have provided

<table border="0" align="center" width="100%">
<tr><td class="header">A
<td class="header">B
<td class="header"><b>C</b>
</tr>
</table>

the necessary result is

<table border="0" align="center" width="100%">
<tr><td class="header">A</td>
<td class="header">B</td>
<td class="header"><b>C</b></td>
</tr>
</table>

I attempted the subsequent reference.

How to use HTMLAgilityPack to repair HTML tags that lack the open> and close> elements

output I received

<table border="0" align="center" width="100%">
<tr><td class="header"></td>A
<td class="header"></td>B
<td class="header"></td><b>C</b>
</tr>
</table>

I'm new to working with HTML files.

I appreciate it.

1
1
5/23/2017 12:15:53 PM

Accepted Answer

A unique option is accessible as a property on the HTML Agility Pack.HtmlDocument kind, namedOptionFixNestedTags addressing these kinds of HTML mistakes:

    static void Main(string[] args)
    {
        HtmlDocument doc = new HtmlDocument();
        doc.OptionFixNestedTags = true;
        doc.Load(YourFile);

        doc.Save(Console.Out);
    }

The result will be:

<table border="0" align="center" width="100%">
<tr><td class="header">A
</td><td class="header">B
</td><td class="header"><b>C</b>
</td></tr>
</table>
2
4/1/2014 8:57:24 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow