Tuesday, April 17, 2012

BPEL ora:countNodes() XPath function usage

Occasionally I have hit the problem where BPEL engine fails to execute the countNodes() function reporting the following error;

javax.xml.xpath.XPathExpressionException: Failed to execute countNodes() function : oracle.xml.parser.v2.XMLNodeList
        at oracle.xml.xpath.JXPathExpression.evaluate(JXPathExpression.java:242)
        at com.collaxa.cube.xml.xpath.BPELXPathUtil.evaluate(BPELXPathUtil.java:247)

Since the BPEL XPath expression builder allows declarative development, it is very tempting and easy to pick the relevant function and insert the BPEL variable from the panels for evaluation. However, for a function such as ora:countNodes(), the catch is that it doesn't expect bpws:getVariableData(blah blah blah) as an argument. Rather, the XPath expression of the variable has to be directly fed into it for proper evaluation.

Apparently, the BPEL XPath function documentation for ora:countNodes() states the following definition;

 ora:countNodes(variableName, partName?, locationPath?)

Hence,  ora:countNodes(bpws:getVariableData(variableName, partName?, locationPath?)) will eventually throw the above error. It is a very simple thing, but can easily miss the unsuspecting eyes :)


  1. Hi. Is there any way I can get in touch with you? Over email? I am an Oracle developer who just started working with Java and SOA. Would like your help in a few doubts.

  2. Yeah. Post your email id on this blog and I will get in touch through email.

  3. Thanks for the article!

  4. How this error?

    javax.xml.xpath.XPathExpressionException: Failed to execute countNodes() function : java.lang.String

    This happens only if I'm counting 90 thousand or more data inside the XML.
    It works fine if i only have less, let's say 60 thousand.

    Any idea?

    1. Looks like a very specific use-case. Can you build a sample project to replicate this error and send it across?

      Also, I would advise you to log a SR with Oracle support for resolution.

  5. i tried all of the above options and i still was unable to get thru the issue. my am reading records from a file and writing to a db. this is how my input variable looks like :-$receiveInput_Read_AtTaskInputVariable.body/ns3:AtTaskRecords and there are more than 1 columns in it. I am trying to get the record count but nothing mentioned in this blog help. But i need help to get this issue resolved.

  6. put it in quotes.I mean to say ora:countNodes('variableName', 'partName', 'locationPath')