Search code examples
c#html-agility-pack

Check the type of a tag


Suppose I have a table that contains a list of tr and th, I need to know if the current tag in iteration is a th or a tr, what I did for the moment:

foreach (var tr in rows)
{   
    if(tr.InnerHtml.StartsWith("<th"))

I'm looking for a more elegant way..


Solution

  • You can use the Name property:

    foreach (HtmlNode node in rows)
    {   
        if(node.Name == "tr")
        {
            // ....
        }
    }