java - XPath getting text from an element after a certain element -
so right if have this:
//div[@class='artist']/p[x]/text()
x can either 3 or 4, or maybe different number. luckily, if looking not in 3, can check null , go on until find text. issue rather know i'm going right element every time. tried this:
div[@class='people']/h3[text()='h3 text']/p/text()
since there <p>
right after <h3>h3 text</h3>
. never returns anything, , results in error. if remove /p 'h3 text' returned.
anyway, how <p>
directly after <h3>
?
btw, i'm using htmlcleaner in java this.
by default when don't specify axis child::
axis, why /
operator seems descend dom tree child child. there implied child::
after each slash.
in case don't want find child of <div>
, want find sibling of it. sibling element @ same nesting level. specifically, should use following-sibling::
axis.
div[@class='people']/h3[text()='h3 text']/following-sibling::p/text()
xpath axes
axes advanced feature of xpath. 1 of features make xpath powerful.
you're familiar 1 other axis, though may not have realized it: @
symbol shorthand attribute::
. when write @href
you're saying attribute::href
, in attribute called "href" instead of child.
axes, eh? shorthand, eh? tell me more, say? ok!
.
,..
shorthand more verboseself::node()
,parent::node()
, respectively. use longer forms if wished.the
//
operator commonly see//p
orbody//a
has hiddendescendant-or-self::node()
between slashes.//p
shorthand/descendant-or-self::node()/p
.
Comments
Post a Comment