htmlagilitypack descendants doesn't return all descendant nodes

22 views Asked by At

When I execute on the li node I only get 7 nodes, stopping with the element. I've tried descendants, but none of them return the div following the text. Is there a way to do this? Here is the structure of the html. Is there some other method I can use? I used vertical bars instead of angle brackets so I could get this posted.

|li|
|div display="flex" class="css-wjome"|
    |span|
        |svg|
            |use||/use|
        |/svg|
    |/span|
    |div|
        |span|stuff|/span|
    |/div|
|/div|
|div|
    |span|
        |div|
            |blockquote|stuff|/blockquote|
        |/div|
    |/span|
|/div|
|/li|
1

There are 1 answers

0
Jonathan Magnan On

Unfortunately, HAP closes the “span” as soon as a “div” is found.

So your current HTML is read similar to this one:

<li>
<div display="flex" class="css-wjome">
    <span>
        <svg>
            <use></use>
        </svg>
    </span>
    <div>
        <span>stuff</span>
    </div>
</div>
<div>
    <span></span>
    <div>
         <blockquote>stuff</blockquote>
     </div>
</div>
</li>

You can easily see this behavior by using OutputHtml as show in this Fiddle: https://dotnetfiddle.net/189Ea1

So that explain why you don't get the stuff text as you probably think it's inside the span tag which is not for HAP.