In C#, how do I get the text of an System.Windows.Form.HtmlElement not including the text from its children?
If I have
<div>aaa<div>bbb<div>ccc</div><div>ddd</div></div></div>
then the InnerText property of the whole thing is "aaabbbcccddd" and I just want "aaa".
I figure this should be trivial, but I haven't found anything to produce the "immediate" text of an HtmlElement in C#. More ludicrous ideas are "subtracting" the InnerText of the children from the parent, but that's an insane amount of work for something that I'm sure is trivial.
(All I want is access to the Text Node of the HtmlElement.)
I'd certain appreciate any help (or pointer) that anyone can supply.
Many thanks.
Examples:
<div>aaa<div>bbb<div>ccc</div><div>ddd</div></div></div> -> Produce "aaa"
<div><div>ccc</div><div>ddd</div></div> -> Produce ""
<div>ccc</div> -> Produce "ccc"
Edit
There are a number of ways to skin this particular cat, none of them elegant. However, given my constraints (not my HTML, quite possibly not valid), I think Aleksey Bykov's solution is closest to what I needed (and indeed, I did implement the same solution he suggested in the last comment.)
I've selected his solution and upvoted all the other ones that I think would work, but weren't optimal for me. I'll check back to upvote any other solutions that seem likely to work.
Many thanks.