public IEnumerable<Xml.IQueryableNode> Parents(Xml.IQueryableNode node) { var curr = node; var result = node.Parent(); while (result != null) { if (string.Compare(curr.Name.LocalName, "tr", StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(result.Name.LocalName, "table", StringComparison.OrdinalIgnoreCase) == 0) { yield return new TbodyNode(curr); } yield return result; curr = result; result = result.Parent(); } var html = new HtmlNode(); switch (curr.Name.LocalName.ToLowerInvariant()) { case "html": // do nothing break; case "body": case "head": yield return html; break; case "title": case "base": case "link": case "style": case "meta": case "script": case "noscript": case "command": yield return new HeadNode(curr, null, html); yield return html; break; default: yield return new BodyNode(curr, null, html); yield return html; break; } }