I have to configure our enterprise search engine and the indexing of documents is done via xpath selectors. In the current setup there is an xpath
.//div[@id='content']
Which selects basically all elements of the main part of a website. Meanwhile there is an additional div with a lot of nonsense included, so I tried to modify this xpath to skip this div-tag. I am struggling with the documentation regarding "not" but withou any luck so far.
<div id="content">
<div id="i-want-this">
...
</div>
<div id="i-do-not-want-this">
<span>foo</span>
</div>
<div id="i-want-this-too">
...
</div>
</div>
While I see that the hints in the comments helped me so far, I still have an issue with child elements in the div-tag I want to skip. Let's say, there is a span-tag inside. If I select
//div[@id='content']/*[not(@id='i-do-not-want-this')] my result still includes this span-content. So I guess, I need a query for all elements below id="content" which do not have a parent id="i-do-not-want-this". Right?
Use the following query. It will select all child elements which id is not i-do-not-want-this
.
//div[@id='content']/*[@id != 'i-do-not-want-this']
or - the same logic - using the ǹot()
function (thanks @paul_t)
//div[@id='content']/*[not(@id='i-do-not-want-this')]
Update
When I said the same logic then this isn't really correct. Pleases visit the comment from @IanRoberts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With