I want to extract //pre
and //code
elements but exclude //pre/code
. For example:
<root>
<pre><code>foo</code></pre>
<code>bar</code>
<pre>baz</pre>
<span>ignore me<code>select me</code></span>
</root>
I want to retrieve four elements:
<pre><code>foo</code></pre>
<code>bar</code>
<pre>baz</pre>
<code>select me</code>
(And I specifically don't want <code>foo</code>
)
The following xpath seems to do the trick:
//*[(self::pre or self::code) and not (self::code and parent::pre)]
I don't know if that's the right approach, but it seems to work.
Is there a less verbose way to express this (e.g. that doesn't require self::
and parent::
)?