Showing posts with label XPath. Show all posts
Showing posts with label XPath. Show all posts

Saturday, July 2, 2011

BPEL XPath function to retrieve values from a list

In BPEL, if you would like to look through a list of XML elements and check certain condition in each element then follow the steps below:

Sample XML:
<employees>
<employee>
<name>NAME1</name>
<age>25</age>
</employee>
<employee>
<name>NAME2</name>
<age>30</age>
</employee>
<employee>
<name>NAME3</name>
<age>35</age>
</employee>
</employees>

We can use "While" Activity for looping through multiple elements but the real task is to access the data within each dynamically:

1. Initialize a simple int "counter" variable and set the value = 0

2. Count the number of employee nodes in employees root node using,
ora:countNodes("employees/employee")
[Note: Use BPEL Expression builder to get the XPath Expression but remember to delete bpws:getVariableData from the expression because we are not looking for data but only number of nodes]

3. Loop through each of the employee node and check if the <age> is greater than 26 as:

bpws:getVariableData('employees','part',"employee[position()=bpws:getVariableData('counter')]")

4. Increment the counter and you will be able to a access all the employee data dynamically.

Things to remember:

1. In BPEL, the index starts with 1 and not 0 so make sure the "counter" value starts from 1 and not 0.
2. Whereever in the XPath you are accessing a variable inside a variable such as, { "employee[position()=bpws:getVariableData('counter')]" } use double quotes for outside variable and single quotes for inside variable
3. Use position() function as shown above

Wednesday, June 29, 2011

Oracle BPEL XPath: How to check if a value exists in a list of values?

Use the following XPath function available within the BPEL XPath function library:

xp20:matches(string(bpws:getVariableData('inputVariable','payload','/ns1:RuntimeFaultMessage/ns1:code')),'^(ABCD)$') = true()

Things to remember:

  • Use string (element data) since the bpws:getVariableData returns an Object and not a string and should be converted to string using th string() function.


  • The above function matches if the variable data has the value equals A or B or C or D using the '^(ABCD)$' and this expression can be replaced with other regular expressions for similar comparisons


  • Use true() and not true for comparing the condition
  • Search This Blog