using XPath: how to exclude text in nested elements

html, nested, xml, xpath

Solution

div[@class = 'unique_id']/text()[not(normalize-space() = '')]

or

div[@class = 'unique_id']/text()[last()]

depending on context.

Note that you still have to trim the resulting text node.

Problem

if I have some html like the following ``` <div class=unique_id> <h1 class="parseasinTitle"> <span> Game Title </span> </h1> Game Developer </div> ``` Is there a way I can use xpath to get JUST the "Game Developer" part of the text? From searching around I tried: ``` //div[@class='unique_id' and not(self::h1/span)] ``` But that still gives me the entire text "Game Title Game Developer".

Original source