xsd:choice, pre-created elements, part 2 - writing a custom xpath function to remove empty elements
Thinking a little bit more on this issue, preferably on a sunday - and voila,
another solution came to my brain. Writing a custom XPATH function that removes
all the empty elements, from a given parent node.
Basically writing an BPEL XPATH function consists of 2 parts:
- a class that implements com.oracle.bpel.xml.xpath.IXPathFunction
- and is registered in xpath-functions.xml, located in $BPEL_HOME/domains/<domain name>/config
Ok, one step after the other
Step 1 - implementing the interface - the only method that is available and will be called is
public Object call(IXPathContext context,
Inside the class it's rather easy to retrieve parts, like the context, or any xpath queried elements as shown below
// retrieve the context ..
Map properties =
(Map) context.getVariableValue(null, null,
ICubeContext cubeContext =
retrieving the xpath element from a query is not much deal too (in this case I expect one argument of type Element)
Element el = (CubeDOMElement) args.get(0)
So the only thing left is implementing an algorithm to search the element (el) for empty nodes .. and remove them ..
Step 2 - registering the function with the BPEL Server
Next, open the xpath-functions.xml, located in $BPEL_HOME/domains/<domainname>/config, and add your new function.
I just copied one of the entries, changed the value of <function> to deleteEmptyElements, the <classname> to point to my new class, and gave the whole thing the right pprefix and namespace (as shown)
<comment>Namespace URI for this function</comment>
<comment>Namespace prefix for this function</comment>
Using your new function in a process:
As written earlier, one argument of type element is expected, which can be easiliy retrieved throug using bpws:getVariableData function.
<to variable="outputVariable" part="payload"
still have questions? send your feedback on writing a custom xpath function here