2

Have the following XML response,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<globalTestList rowCount="1">
    <testcase>
        <checkedOut>N</checkedOut>
        <group name="PerfTest105" recid="2489"/>
        <testImportance>0</testImportance>
        <testRecid>2491</testRecid>
        <testType>Conventional Function Test</testType>
        <preFetched>Y</preFetched>
        <priority>6</priority>
        <series>Functional</series>
        <test id="98132" recid="2401"/>
        <subject number="98132" recid="2476"/>
        <testCode>555210</testCode>
        <userId>1201</userId>
        <test name="Functional Test 1" recid="2478"/>
        <workflowChangeDate>2023-06-28T13:07:08Z</workflowChangeDate>
        <workflowState>Testing.Imported</workflowState>
    </testcase>
</globalTestList>

What to retrieve the recid from <group name="PerfTest105" recid="2489"/>. Specifically it should be associated group attribute which is 2489 as there are other recid as well.

Know values from previous response are,

know from previous response recid="2478" and recid="2401" & 555210.

Is there a way using xpath/ regex I can fetch the recid for the group. also cannot trust group name="PerfTest105" as it is dynamic too.

I tried with //timsCode[text()='555210']/parent::*/@recid but not working

Dev030126
  • 315
  • 1
  • 8

2 Answers2

1

You almost solved it,

your xapth should be //testCode[text()='555210']/parent::*/group/@recid

enter image description here

enter image description here

Jyoti Prakash Mallick
  • 2,119
  • 3
  • 21
  • 38
1

I would suggest going the other direction, in this case you will be able to avoid selection of all nodes followed by filtering and doing it twice when you're matching the parent.

The following XPath expression should work for you:

/globalTestList/testcase[testCode='555210']/group/@recid 

More information:

Using regular expression extractor for getting data from non-regular languages is not the best idea.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133