Oracle SOA BPEL access dynamic xml payload element using XPath


In my this post, I'll showcase the scenario of accessing the XML elements for dynamic payload received. I am using Oracle SOA Suite 11g & BPEL 1.1, however same should work on higher versions also. So let's get started-


Use case:

I was given the below XML payload 



Note that elements inside TargetEntity are dynamically generated at runtime.

Corresponding XML schema is




What we need to access

To access the Value of  DataAttribute Name i.e.  district/ usr_circle/ Mobile etc.

Solution

Use XPath expression builder in your BPEL Process for assignment and use below code for the same:

bpws:getVariableData('requestDetails','RequestData','/ns18:RequestData/ns18:TargetEntityData/ns18:TargetEntity/ns18:DataAttribute[@Name="NameAttribute"]/@Value')

Here NameAttribute refers to district/ usr_circle/ Mobile. So to access the value of attribute Name 'district', the XPath expression would be:


bpws:getVariableData('requestDetails','RequestData','/ns18:RequestData/ns18:TargetEntityData/ns18:TargetEntity/ns18:DataAttribute[@Name="district"]/@Value')


This will return Gurgaon

UPDATE[30-May-2019]
In addition there is also mechanism to access the dynamic payload when required data is available as XML node instead of attribute. Consider the below XML-
__________________________________________________________________
..............................
...............
<otherAttributes>
 <name>CustID</name>
 <value>640981</value>
</otherAttributes>
<otherAttributes>
 <name>CustName</name>
 <value>Mr Kumar Gaurav</value>
</otherAttributes>
...............
..............................
__________________________________________________________________

XPATH Expression-
bpws:getVariableData('CreateOp_InputVariable','parameters','/ns2:create/userAccount/otherAttributes[name="CustID"]/value')

Expression output-
This expression will return 640981

Important to notice that there is no need to put '@' symbol as previously used to access the attribute.

That's all!




Comments

Popular posts from this blog

Oracle SOA Suite- Implementing Email Notification

Oracle SOA Suite 12c- PKIX path building failed & unable to find valid certification path to requested target

Migration of Oracle SOA Suite Composite from 11g to 12c