0

I have two WebService(SOAP) Requests. The responses of both web service calls are exactly the same structure-wise. For web service call number 1, it has the following structure,

  <data xsi:type="soapenc:string">0</data>
  <data xsi:type="soapenc:string">650</data>

For web service call number 2, it has the following structure,

  <data xsi:type="soapenc:string">0</data>
  <data xsi:type="soapenc:string">10203</data>

Under each of these calls, I have a regular expression extractor. The reference names are different; but everything is defined exactly the same. The extractor has the following definitions.

Apply to: Main Sample Only
Response Field to check: Body
Regular Expression: <data xsi:type="soapenc:string">(\d+?)</data>
Template: $1$
Match No.: 0

For the web service call number 1, the extractor gets the value of 650, which is what I want. But for the web service call number 2, the extractor actually gets the value of 0, which is NOT what I want. What I want to get in the web service call number 2 is 10203. My question is, why is it that the regular expression extractor definitions would return two different results?


Thanks in advance,
Monte

Monte Chan
  • 1,193
  • 4
  • 20
  • 42

4 Answers4

3

If you're using a match number of zero it will pull a value for your regular expression at random. 0 = Random Match, 1 = first match, 2 = second, etc...

MrTunaDeluxe
  • 152
  • 5
  • 20
  • Thank you very much for your help. By changing the match number if the other web service calls, the values are extracted correctly now. – Monte Chan Jun 04 '12 at 16:38
2

Looks like you've asked already same question here.

  1. Use either Regular Expression Extractor or XPath Extractor - which one is more preferable for parsing xml, as mentioned in comments above, - with the single expression - (for RegEx Extractor: <data xsi:type="soapenc:string">(.+?)</data>, for XPath Extractor: //data/text() - to get ALL the matches.
    Then use corresponding generated variable to access match you need - via ${refName_2} e.g. (to access 2nd match extracted by query to refName variable), this is actual for both RegEx and XPath Extractors, - or force RegEx Extractor to use specific match by default, via setting "Match No." (to 2 as per above example).

  2. Use XPath Extractor with xpath query which will uniquely describe required value among the other: by fixed position - like //data[position()=2]/text() in your case (presume that first match is always 0 and you need the 2nd), - or by value - comparing match's text() to 0 like //data[text()!=0]/text().

Community
  • 1
  • 1
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
0

I am puzzled by the ? in your regular expression: (\d+?). This means "one or more digits, but optionally."

Given your input data from call number 1 and call number 2, I would expect it to match the first line in both cases, <data xsi:type="soapenc:string">0</data>, but you say that it doesn't.

I suspect that don't want to match a number with a leading zero. So I would suggest

Regular Expression: <data xsi:type="soapenc:string">([1-9]\d*)</data>
David Gorsline
  • 4,933
  • 12
  • 31
  • 36
0

Given web service calls

For web service call number 1, it has the following structure

<data xsi:type="soapenc:string">0</data>
  <data xsi:type="soapenc:string">650</data>

For web service call number 2, it has the following structure

<data xsi:type="soapenc:string">0</data>
  <data xsi:type="soapenc:string">10203</data>

we can extract the values 650 from the web service call number1 in the following formats

</data>\s\s<data xsi:type="soapenc:string">(.+)</data>
or
</data>\s\s<data xsi:type="soapenc:string">([0-9]+)</data>

we can extract the values 10203 from the web service call number 2 in the following formats

</data>\s\s<data xsi:type="soapenc:string">(.+)</data>
or
</data>\s\s<data xsi:type="soapenc:string">([0-9]+)</data>