Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How can I use an XPATH with a parameterized value in a rest call

BrianQuantum
BrianQuantum Posts: 23

I have a GET that stores values in a Datasource using an XML Databank
I then want to extract a value from my next GET based on value in the Datasource.

For example, say in the first GET, I store 2 for the number of widgets in the Datasource.
Then the next GET has another XML Databank that extracts one part for each widget - in this case, 2 widgets. If I always knew the that number of wdgets was 2, then I could have 2 requests with the following XPATHs:
/:partList/part[][partType=7][1]/location[1]/text()
/:partList/part[][partType=7][2]/location[1]/text()

But since I don't know the number of widgets, I need a way to parameterize the number in the XPATH based on the number of widgets in the Datasource, e.g.,

/:partList/part[][partType=7][{$numberOfWidgets}]/location[1]/text()

Best Answer

Answers

  • OmarR
    OmarR Posts: 233 admin
    edited June 2017

    Mr. Quantum,

    Have you tried wrapping your xpath in "count(xpath)" to determine the count of a particular element?

    For example,
    count( /:partList/part[][partType=7]/location/text() )

    You may then store this value in DataSource column and parameterize it using ${numberOfWidgets}

  • BrianQuantum
    BrianQuantum Posts: 23

    Omar, Thank you. Perhaps I am thinking about this wrong but my challenge is then getting that count result into an XPATH. How does one do that?

  • BrianQuantum
    BrianQuantum Posts: 23

    Thank you, this now makes sense and works.