html - How to select text in a node whether or not inside another tag -


i trying write xpath selector extracts names may or may not inside span, i.e., both fragments below:

<p class='out'> <span>john</span> </p>  <p class='out'> alice </p>  <p class='out'> <span>tim</span> </p>  <p class='out'> doe </p>  <p class='out'> <span>tina</span> </p>  <p class='out'> joseph </p> 

i able write individual cases, how do both?

this attempt:

//p/span/text()

you can use or -> | operator achieve requirement

try below:-

 //p[not(self::span)] | /span 

hope :)


Comments