private bool MatchesNode(object node, TextSearch search)
 {
     if (node is HtmlElementNode htmlElementNode)
     {
         return(search.IsMatch(htmlElementNode.TagName) ||
                MatchesAttributes(htmlElementNode.Attributes, search));
     }
     else if (node is HtmlCDataNode htmlCDataNode)
     {
         return(search.IsMatch(htmlCDataNode.InnerHtml));
     }
     else if (node is HtmlTextNode htmlTextNode)
     {
         return(search.IsMatch(htmlTextNode.Text));
     }
     else if (node is HtmlHeaderNode htmlHeaderNode)
     {
         return(MatchesAttributes(htmlHeaderNode.Attributes, search));
     }
     else if (node is XmlHeaderNode xmlHeaderNode)
     {
         return(MatchesAttributes(xmlHeaderNode.Attributes, search));
     }
     else if (node is SoftCircuits.HtmlMonkey.HtmlDocument)
     {
         // Root node
     }
     else
     {
         Debug.Assert(false);
     }
     return(false);
 }
 private bool MatchesAttributes(HtmlAttributeCollection attributes, TextSearch search)
 {
     foreach (var attribute in attributes)
     {
         if (search.IsMatch(attribute.Name) || search.IsMatch(attribute.Value))
         {
             return(true);
         }
     }
     return(false);
 }