Assuming I have an instance of HtmlNode
pointing to table, how can I remove all nodes above and below it?
we can assume table is in the same level of html and body tag
<html>
<body>
<p>please remove me</p>
<table>
....
</table>
<p>please remove me</p>
<a> ... </a>
.
<img>...</img>
</body>
</html>
According to your HTML sample (and commonly it is),
<table>
is child of<body>
, they are not at the same level. Assuming thattable
is a variable of typeHtmlNode
pointing to the<table>
element, you can do this way :brief explanation about XPath being used :
following-sibling::*[1]
: select direct following sibling element regardless of the element name.preceding-sibling::*[1]
: select direct preceding sibling element regardless of the element name.|
: XPath union operator to combine two different XPath expressions