Wednesday, June 25, 2014

Xquery or XPATH to check for the existence of element

This is a very common validation in BPEL or OSB to find  if an element or child element exist in xml or not. In OSB there are xquery function like fn:exists() can be used to achieve this. But in BPEL there is no direction function available to check for the existence of element. So here is an alternate way to do that. The xpath function countNodes can count the number of nodes present in the element or under that element as child element.

ora:countNodes('inputVariable','payload','/ns1:process/ns1:File/ns1:Content/ns1:XMLContent/*')>0

Note the first parameter in the function which is variable name and the value is 'inputVariable' instead of '$inputVariable'. The function accepts only variable name as parameter.

Second is part name and third one is the exact path after part name.

The above function is used to find out if the anytype element 'XMLContent' has any child elements or not. The schema is below -


Another way to use (see SAARequester) countNode is this -

ora:countNodes('saaVar','ns4:Body/*')=0

where saaVar has no part name and it has this structure -

Demystifying OIC, OCI and Oracle SOA CS

What is OIC (Oracle integration cloud), OCI (Oracle cloud infrastructure), and SOA cloud service and how they are different? - This has bee...