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.

Fetching a data based on key without mentioning array position

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

Hi Team,
we are trying to create job id for the splunk, where as job id is coming in different locations of the response.
** 1**
we are trying to extract using this position 20, every time it comes in different position.

/:entry/:content[1]/:dict[1]/:key[20]/text()

I also tried key[name="isDone"], but no luck

Any help would be really appreciated.

Thanks
Udaya

Tagged:

Comments

  • jakubiak
    jakubiak Posts: 795 admin

    There are two different approaches you could take:
    1. Use an XPath that keys on a different attribute that is not dependent on the order within the array
    2. Use the XML Sort tool to sort the data before applying your XML Data Bank or XML Assertor. If using JSON, you can use the XML Convertor Tool to convert to XML and then attach the XML Sort tool.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    @jakubiak

    Both the options wont work for me,
    1st wont work, there is no other unique element to identify
    2nd one also wont work, as we are getting different set of array elements every time. Even though you order the response, array representation is same.

    some issue in editor, representing as image.

  • OmarR
    OmarR Posts: 233 admin

    Good morning,

    Try using @ to get the attribute value of "name" in your xpath condition.
    For example:
    /entry/*:content/*:dict/*:key[@name='isdone']/text()

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Thanks Omar :smile: It helped us.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    I also tried key[name="isDone"], but no luck

    To clarify, that works fine if "isDone" is the name of a simple element. I provided a similar example recently. Similar questions have been posted to the forum recently:
    assertor option when the response tree is changing
    Validating responses when order of individual elements changes

Tagged