Fetching a data based on key without mentioning array position

ParasofttoudayaParasofttoudaya Posts: 200 ✭✭

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

  • jakubiakjakubiak Posts: 371 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.

  • ParasofttoudayaParasofttoudaya Posts: 200 ✭✭

    @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.

  • OmarROmarR Posts: 206 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()

  • ParasofttoudayaParasofttoudaya Posts: 200 ✭✭

    Thanks Omar :smile: It helped us.

  • benken_parasoftbenken_parasoft Posts: 552 ✭✭✭

    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

Sign In or Register to comment.