Subject:Xpath predicate numeric vs string help... Author:Sean Symes Date:12 Jul 2005 06:36 AM
Hi all,
I've got a problem using predicates when searching on values of elements. In short the xpath statement below works if the value of an element in the predicate part is numeric, if however I change the value of the element to a string it doesn't work.
See the two code snippets below;
----- WORKS -----
XML (element value is 3)
<loop name="Party Identification">
<segment name="Name and Address">
<element ref_des="NAD01">
3
</element>
<element ref_des="NAD03">
Hello world
</element>
.... other elements I want to get data from
----- FAILS -----
XML (element value is 'ABC')
<loop name="Party Identification">
<segment name="Name and Address">
<element ref_des="NAD01">
ABC
</element>
<element ref_des="NAD03">
Hello world
</element>
.... other elements I want to get data from
Thanks Ivan for your help.
I worked out the problem, basically the value for "<element ref_des="NAD01">" was on the next line with spaces preceeding it to "tab" it in, with the corresponding end tag on the line below that. When doing a string search the xpath parser was including the preceeding spaces as part of the search criteria. Take out the "formatting" and the statement worked, this also explains why numerics were working.