Search code examples
c#htmlhtml-agility-pack

Unable to understand behaviour of node.childrens


<tr>
<th style="text-align: center; background: #f08080;" colspan="3">خدیجہ مستور</th>
</tr>

when iterating using htmlagilityPack using node.children (recursively) i am getting this output:

tr
 |->#text:
 |->th
  |-->#text: خدیجہ مستور
 |->#text:

using node.childrens gives 3 childrens of tr tag : #text,th,#text i just want to iterate such that only direct childrens iterated first and then childrens of children. i am confused to get #text two times as child of tr from where these two #text are coming??? or what is this behavious can anyone explain it to me?


Solution

  • The output is as expected.

    There are two, empty text nodes in the markup - before the <th> and after it - the line breaks count.

    You can exclude empty text nodes in your output.