I am trying to extract text from a node in an XHTML page using XPath but I am having trouble to collect ALL the text below a given node.
The problem is, that a node (see for example the p-element in the example below) can have multiple children nodes (in the example e.g. "b" and "em") and multiple text fragments interspersed ("aaaa", "bbbb" and "cccc"). My XPath expression "p/text()", however, returns me only the first text "aaaa" while I need to collect ALL text fragments directly underneath the p-node, i.e. I want to obtain "aaaabbbbcccc" (but not foo and bar). How do I teach XPath to collect ALL texts and return them as one concatenated string?
...
<p>
aaaa
<b>foo</b>
bbbb
<em>bar</em>
cccc
</p>
...
Alternatively: what would be the XPath expression to get a list of all text-fragments, so I can concatenate them programmaticallyin my code?