How to Use SOAP-Encoded Arrays

6-48 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite The code in Example 6–90 calculates the number of elements in the item sequence and assigns it to the integer variable lineItemSize. Example 6–90 Sequence Size Determination assign copy from expression=countbpws:getVariableData’outpoint’, ’payload’, p:invoicep:lineItemsp:item to variable=lineItemSize copy assign

6.19.4 How to Dynamically Index by Applying a Trailing XPath to an Expression

Often a dynamic value is needed to index into a data sequence; that is, you must get the nth node out of a sequence, where the value of n is defined at runtime. This section covers the methods for dynamically indexing by applying a trailing XPath into expressions.

6.19.4.1 Applying a Trailing XPath to the Result of getVariableData

The dynamic indexing method shown in Example 6–91 applies a trailing XPath to the result of bwps:getVariableData, instead of using an XPath as the last argument of bpws:getVariableData. The trailing XPath references to an integer-based index variable within the position predicate that is, [...]. Example 6–91 Dynamic Indexing variable name=idx type=xsd:integer ... assign copy from expression=bpws:getVariableDatainput,payload p:line-item[bpws:getVariableDataidx]p:line-total to variable=lineTotalVar copy assign Assume at runtime that the idx integer variable holds 2 as its value. The preceding expression within the from is equivalent to that shown in Example 6–92 . Example 6–92 Equivalent Format from expression=bpws:getVariableDatainput,payload p:line-item[2]p:line-total There are some subtle XPath usage differences, when an XPath used trailing behind the bwps:getVariableData function is compared with the one used inside the function. Using the same example where payload is the message part of element p:invoice, if the XPath is used within the getVariableData function, the root element name p:invoice must be specified at the beginning of the XPath. Example 6–93 provides details. Example 6–93 Root Element Name Specification bpws:getVariableDatainput, payload, Manipulating XML Data in a BPEL Process 6-49 p:invoicep:line-item[2]p:line-total If the XPath is used trailing behind the bwps:getVariableDatafunction, the root element name does not need to be specified in the XPath. For example: bpws:getVariableDatainput, payloadp:line-item[2]p:line-total This is because the node returned by the getVariableData function is the root element. Specifying the root element name again in the XPath is redundant and is incorrect according to standard XPath semantics.

6.19.4.2 Using the bpelx:append Extension to Append New Items to a Sequence

The bpelx:append extension in an assign activity enables BPEL process service components to append new elements to an existing parent element. Example 6–94 provides an example. Example 6–94 bpelx:append Extension assign name=assign-3 copy from expression=bpws:getVariableDataidx+1 to variable=idx copy bpelx:append bpelx:from variable=partInfoResultVar part=payload bpelx:to variable=output part=payload bpelx:append ... assign The bpelx:append logic in this example appends the payload element of the partInfoResultVar variable as a child to the payload element of the output variable. In other words, the payload element of the output variable is used as the parent element.

6.19.4.3 Merging Data Sequences

You can merge two sequences into a single data sequence. This pattern is common when the data sequences are in an array that is, the sequence of data items of compatible types. The two append operations shown in Example 6–95 under assign demonstrate how to merge data sequences: Example 6–95 Data Sequences Merges with append Operations assign -- initialize mergedLineItems variable to an empty element -- copy from p:lineItems from to variable=mergedLineItems copy bpelx:append bpelx:from variable=input part=payload query=p:invoicep:lineItemsp:lineitem bpelx:to variable=mergedLineItems bpelx:append