AngleSharp - Find innermost nested tables

432 Views Asked by At

I try to get a list of all innermost tables with AngleSharp. This tables doesn't contain any tables.

With HtmlAgilityPack I've realised it this way:

    var wrapper = html.DocumentNode.SelectSingleNode(".//td[@class='wrapper']");
    var innerMostTables = wrapper.SelectNodes(".//table [not(descendant::table)]");

With AngleSharp I've tried this, but it doesn't work:

    var parser = new HtmlParser();
    var document = parser.Parse(html);

    var wrapper = document.All.Where(d => d.ClassName == "wrapper");
    var innerMostTables = wrapper.Where(w => w.Descendents()
                                     .Select(c => c.NodeName == "table").Count() == 0);
1

There are 1 best solutions below

0
On

I could solve the problem:

    foreach (IElement ch in wrapper.Descendents()
             .Where(d => d.NodeName == "TABLE" && d.Descendents()
                 .Where(d2 => d2.NodeName == "TABLE").Count() == 0))
    {
        Console.WriteLine(ch.OuterHtml);
    }