db2 - Filtering XML using multiple conditions of xquery -
hi have many xml files have structure like:
<mydoc> <ec> <spec> <name>a para</name> <para>a</para> <val>40</val> </spec> <spec> <name>input voltage</name> <para>vin</para> <val>40</val> </spec> </ec> </mydoc>
i need filter out xml files has spec para=vin , val>30
what should xquery like? in db2 have far?
for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc
so iterate on xml files , have mydoc element tag in $x how implement multiple conditions , return name of spec satisfies conditions?
there couple ways express this. xpath predicates:
for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc[ec/spec[para = 'vin' , val > 40]]
or xquery's where
clause. uses xpath predicates , think easier read:
for $x in db2-fn:xmlcolumn('table.xmlcolumn')/mydoc let $specs := $x/ec/spec ($spec[para = 'vin' , val > 40])
both should give same results.
Comments
Post a Comment