XPath locates text between two tags
P粉462328904
P粉462328904 2023-09-13 20:02:12
0
1
480

I need a way to select text between two tags (the first tag and the subsequent
tag):

<div>
<span>abc</span>
defg
<br>
hijkl
<br>
mnop
<span>qrs</span>
tuvw
<br>
xyz
</div>

How to select only "defg" using xpath expression?

I tried using following-sibling to find the first tag after the first
tag, but I can't find a way to select the text between them.

P粉462328904
P粉462328904

reply all(1)
P粉553428780

Use this XML input,

<div>
<span>abc</span>
defg
<br/>
hijkl
<br/>
mnop
<span>qrs</span>
tuvw
<br/>
xyz
</div>

XPath expression/div/span[1]/following-sibling::text()Returns the 5 sibling text nodes after the first element: defg, hijkl, mnop, tuvw, and xyz, each node starts and ends with a newline character.

XPath 1.0 expression normalize-space(/div/span[1]/following-sibling::text()) will return defg, with no leading or trailing whitespace, As an argument to normalize-space(), convert it to a string by returning the string value of the node in the node set that is in document order It's the first.

In XPath 2.0 and later, select the first item in the sequence, for example:
normalize-space((/div/span[1]/following-sibling::text())[1]), this also works in XPath 1.0.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template