Any way to associate HtmlAgilityPack classes with .NET Html classes?

Jun 22, 2010 at 5:10 AM
I could really use some way to cast from a System.Windows.Forms.HtmlElement to a HtmlNode, or something similar. Basically what I wan't to do is combine a .NET WebBrowser.Document with the HtmlAgilityPack to do stuff like getting the XPath to an element that the user clicks.
Jun 8, 2012 at 2:29 AM

I apologize for reviving an old topic, but did anybody manage to achieve this?

Jun 8, 2012 at 6:57 AM

The only thing I can think of is generating a GUID for each element and assigning it to a custom attribute such as "data-my-custom-attribute", which is kinda what jQuery does to keep track of elements. Then you could traverse the DOM on each side and create a dictionary that relates both sides.

Jun 8, 2012 at 12:10 PM

 Like in any other programming thing ... you need the idea, everything else is simple. THANKS FOR THE IDEA!

Actually things are a lot simpler right now.


 Let's say you have HTMLElement <div class="the class">hello man</div>

 You want to get the HTMLNode corresponding to this element.

 Well we add the random attribute (like you said) and our HTMLElement becomes <div class="the class" my_attr="123124"> hello man</div>

 Now we load the htmldocument doc with the new html (that has our element edited) and get the node by using a simple //div[@my_attr='123124']


 Thank you!