Reputation: 1316
I'm trying to extract some data from an xml file where the position is 30 and it contains the word 'mardi'. I've tried several variations, this being the latest one:
//ns:RESULTSET/ns:ROW/ns:COL[position()=30 and contains(text(),'mardi')]
It doesn't return anything, yet when I run:
//ns:RESULTSET/ns:ROW/ns:COL[position()=30]
it returns:
<ns:COL><ns:DATA>mardi</ns:DATA></ns:COL>
<ns:COL><ns:DATA>logement coopératif</ns:DATA></ns:COL>
What is the correct syntax to get what I want? I'm using
Xacobeo
on linux, if that makes any difference.
Thanks
Upvotes: 1
Views: 39
Reputation: 89295
Your attempted XPath didn't work because the text 'mardi' is nested within ns:DATA
element, not direct child of ns:COL
. By using text()
in predicate, only direct child text node of context element (ns:COL
in this case) is evaluated.
To evaluate the entire text within context element, use .
instead :
//ns:RESULTSET/ns:ROW/ns:COL[position()=30 and contains(.,'mardi')]
or maybe you want to explicitly evaluate text within ns:DATA
child element :
//ns:RESULTSET/ns:ROW/ns:COL[position()=30 and contains(ns:DATA,'mardi')]
Upvotes: 1