Reputation: 1561
I want to highlight nodes covered by a given XPath in an HTML page source.
I looked to in HtmlUnit, could not find any thing in API.
At present, I am thinking of doing it following way:
In this way, I will visit all nodes covered by Xpath. With some more changes I can remove those elements which were unnecessarily highlighted.
This is too complicated. Is there a way to do this ?
Upvotes: 1
Views: 364
Reputation: 155
I recently made a rudimentary implementation using JavaFX's WebEngine + WebView. Register a DOM listener to all the nodes of the loaded website's Document, so you can listen to clicks on those Nodes. When clicking, change the style of the Node and add some CSS. WebView will reflect the changes and render the page correctly.
The Document that WebEngine returns can also be accessed using XPath (it's a w3d document), so you can traverse it and modify all the nodes you encounter (or use the Node that is the furthest down, then travel upwards using getParent(), and modify each parent as well).
Upvotes: 1