关闭标记后的XPath数据

I have this HTML: <span id="bla">text</span>more text

I want to get text and more text.

I have this XPath: //span[@id="bla"]/text()

I can't figure out how to get the closing tag and what comes after it.

<span id="bla">text</span>more text alone is not well-formed and cannot be processed via XPath.

Let's put it in context:

<div><span id="bla">text</span>more text</div>

Then, you can simply take the string value of the parent element, div:

string(/div)

to get

textmore text

as requested.


If there's other surrounding content that you don't want:

<div>DO NOT WANT<span id="bla">text</span>more text<b/>DO NOT WANT</div>

You can follow @alecxe's lead with the following-sibling:: axis and use concat() to combine the parts you want:

concat(//span[@id="bla"], //span[@id="bla"]/following-sibling::text()[1])

to again get

textmore text

as requested.

The more text is called a "tail" of an element and can be retrieved via following-sibling:

//span[@id="bla"]/following-sibling::text()