Count the XML nodes in xpath expression
I’m gonna to extend my blog further and will show you how to retrieve total no of nodes.
1) Let’s open the RestPipeline and drag a Assign activity in the Response pipeline.
2) Open the Assign activity properties, give the variable name as totalCount, open the Assign activity Expression, move to the Namespace tab. Add the name space.
Note: URI: http://xmlns.oracle.com/pcbpel/adapter/db/top/DBReference, belongs to the DB adapter XSD. This must be added. You can get the same from DB adapter XSD or business service output.
3) Move to the Variables tab and add the expression: xs:int(count($serviceOutput/db:Employees))
a) serviceOutput: This is the variable that was used in the service callout activity to assign the business service output.
b) db:Employees: This is the node that we want to count.
4) Run the pipeline directly and see the output of totalCount variable
That’s it.
Thanks!
Why are we adding namespace explicitly, as i tried myself will be able to count the node by using default namespace.
Namespace default: fn:count($serviceOutput/dbr:SchemaVersionRegistry)
Namespace explicitly: xs:int(count($serviceOutput/DB:SchemaVersionRegistry))
Quick question: Where are we using Namespace explicitly or how would i know that when will i add the Namespace. Is there any error message that we miss here.
Thanks
Tushar Varshney