IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing business processes > Building BPEL processes > Defining BPEL process logic > Work with XPath in the BPEL process editor

XPath usage overview

This topic provides an overall description of how you can work with XPath in a BPEL process.


Assign activity

You can use XPath to reference parts of a BPEL variable as from-statement or as to-statement in an assign activity. The referenced part of the from-statement is copied and set to the indicated to-statement part. If the to-statement part has not been initialized yet, it is automatically created for you. This also implies that all intermediate business object parts are created if necessary. To assign a string to the XPath /deliveraddress/street as shown in the screen capture below, the property deliveraddress of type Address does not need to exist. Even the BPEL variable customer does not need to be initialized before, instead, it will be automatically created by the assign activity.

An XPath expression may reference simple data types (for example, strings, integers) as well as complex data types. While using the BPEL process editor, there is no verification if an assignment is correct regarding the data type of from-statement and to-statement parts. If you assign a part of a BPEL variable which is a simple data type, the IBM Process Server will convert it to the appropriate target simple data type if applicable. So, for example, assigning an integer value to a string part of a variable is permitted. Nevertheless, if working with business objects, no data conversion will happen at all. You will have to make sure to assign only parts which are either convertible (simple types) or identical typed (simple types and business objects).

While you may use arbitrary XPath functions (see XPath extension functions) for the from part of an assign activity, support for using them on the to part is limited to the child:: and attribute:: axes (see also technote http://www-1.ibm.com/support/docview.wss?&uid=swg21222985).

Be sure to address the to part by an XPath statement without functions, (for example, /customers/address[1]/name).

If you fill an array property using assign activities, be sure to access them sequentially for the to part. So, first you need to fill /customers/address[1]/name before you fill /customers/address[2]/name (array indexes in XPath start with index 1). Otherwise you get an exception during execution in IBM Process Server which will be thrown as the standard fault bpws:mismatchedAssignmentFailure. Also note that sibling functions are not allowed in a to-statement, if the referenced node hasn't been initialized before.


Conditions and expressions

At several places in the BPEL process editor, you can also use XPath based conditions and expressions. This includes conditions on links in parallel activities, the join behavior on arbitrary activities within parallel activities, conditions in choice activities and while loop activities, expressions in the wait activity and the timeout expression in the receive choice activity. In addition, the ForEach activity may use XPath for its start and end expressions, as well as an XPath condition for its exit criterion.

In assign activities, XPath statements are used to reference a from-part and a to-part to be used for an assignment. Nevertheless, conditions and expressions need to have a specific return value. Therefore, you need to make sure your XPath points to a part in a BPEL variable that has the appropriate type (for example, Boolean for conditions). Otherwise, you need to use XPath to build such an type, (for example, bpws:getVariableData(“customer”, “deliveraddress/zip”)=”12345”).


Example

To see an example of how to use XPath in a BPEL process that you can build and run yourself, go to http://publib.boulder.ibm.com/bpcsamp/index.html, and click Advanced BPEL features > XPath.

You will need a connection to the internet to view this example.

Work with XPath in the BPEL process editor


Related concepts:
Choose between XPath and Java in your BPEL process
XPath extension functions