Enter your keyword

post

Count the XML nodes in xpath expression

This blog explain, how to get total no of nodes in the xpath expression. This is very basic and useful post.

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.

Some Toughts (2)

  1. added on 22 Mar, 2017
    Reply

    Thanks!

  2. added on 20 Jun, 2017
    Reply

    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

Leave a Reply

Your email address will not be published.