tags:

views:

23

answers:

1

I'm using xpath 1.0 to parse an html file and I want to get a string sequence from a node-set. First I select a node-set (eg: //div) and then I want the string-value of each node of the set. I've tried with string(//div) but it only returns the string-value of the first node in the set.

Example
<foo>
<div>
bbbb<p>aaa</p>
</div>
<div>
cccc<p>aaa</p>
</div>
</foo>

I expect a result like ('bbbbaaa', 'ccccaaa') but I only get 'bbbaaa'

A: 

In XPath 1.0 the "string-value of a node-set" is by definition the string value of the first node in the node-set.

In XPath 2.0 the following expression produces a sequence of the string values of all div elements in an XML document:

//div/string(.)
Dimitre Novatchev