Question

I'm trying to come up with a complex xPath expression but I can't figure out how to do that. Imagine you have some HTML like this:

<span>
    something1
    <br>
    something2
    <br>
    something3
</span>

Imagine that sometimes the second <br> and the subsequent "something3" are not present. I would like to create an xPath expression that takes all the span nodes and its content up to the first <br> so that I end up parsing just "something1". I don't know if this is possible, if not does anyone know a way to get that after having parsed all the <span> nodes?

I have to say that I'm using HtmlParser, which is a Java library which parses HTML and supports xPath expressions.

Thanks,

Masiar

Was it helpful?

Solution

I'm a bit confused by your description of the problem, but it sounds something like

//span/br[1]/preceding-sibling::text()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top