1

I am trying to select a divs, spans, labels, etc basically any element with a certain attribute.

IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("itemtype"));

Is there a way to rope all descendants into one like above? Since above only finds divs obviously. I am trying to avoid duplicate code to add a whole extra line to replace one word.

For Example (Doesn't work)

IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("*").Where(d => d.Attributes.Contains("itemtype"));
Adam
  • 3,615
  • 6
  • 32
  • 51

1 Answers1

4

Try:

IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants()
   .Where(d => d.Attributes.Contains("itemtype"));
Richard Deeming
  • 29,830
  • 10
  • 79
  • 151