Hi everyone,
I'm running into some difficulty with xpath_eval. I have a function that
loops through the results of xpath_eval when the index is set to 0 to have
it return a vector of results. However I'm getting unexpected behaviour.
My test function is below. The function is commented to indicate what I am
expecting vs what I am getting.
create procedure test_xml_parser()
{
declare xml_str any;
declare i int;
declare xml_inner any;
i:= 0;
xml_str :=
xtree_doc('<output><person><pin>98765</pin></person></output><output><person><pin>12345</pin></person></output>');
dbg_printf('\nStart');
dbg_obj_print(xml_str);
-- Create a vector of <output> tags from xml_str and loop through them
foreach(varchar xml_output IN xpath_eval('//output',xml_str,0)) do {
dbg_obj_print(xml_output);
-- dbg_printf(xml_output); This line errors. xml_output is still
considered an xml_entity despite casting to varchar as part of the foreach
dbg_printf(cast(xml_output as varchar)); --This line returns the value
contained between the <pin> tags and not the expected <output> tags.
dbg_printf('Person start');
dbg_obj_print(xpath_eval('//person', xml_output,0)); --Returns all
instances of <person> found in xml_str and NOT the single instance of
<person> found in xml_output
dbg_printf('Person end');
}
I am quite confused about what is going on. My expectation is that for
each loop of the outer foreach I will see 1 instance of the <person> tags
returned as only 1 instance of <person> is contained in any given
<output></output> set.
Regards,
Peter Secomb
clearbluewater.com.au