Jmeter Regular Expression Extractor find ItemID in xml

I am new to ; I hope that I will tell you well enough about my problem.

I am trying to use regex to retrieve the ItemID attribute from an xml element. Which I then use in another request. This is the XML response I'm trying to extract from ItemID:

<?xml version="1.0" encoding="UTF-8"?> <Promise > <SuggestedOption> <Option TotalShipments="1"> <PromiseLines TotalNumberOfRecords="1"> <PromiseLine ItemID="Col_001" > <Assignments> <Assignment InteractionNo="1" > </Assignment> </Assignments> </PromiseLine> </PromiseLines> </Option> </SuggestedOption> </Promise> 

I have a regex extent configured as follows:

 Reference Name: item Regular Expression: .?ItemID=(.+?)* Template: $1$ Match No.: 1 

In the second query, I set ItemID as follows: ItemID = $ {item} ...

I know that when I use the default value set to "Col_001", it works fine. Thus, it is obvious that the problem is with my expression.

+4
source share
3 answers

Try the following expression:

 \bItemID\s*=\s*"([^"]*)" 

Explanation

 NODE EXPLANATION -------------------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char -------------------------------------------------------------------------------- ItemID 'ItemID' -------------------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- = '=' -------------------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- " '"' -------------------------------------------------------------------------------- ( group and capture to \1: -------------------------------------------------------------------------------- [^"]* any character except: '"' (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- ) end of \1 -------------------------------------------------------------------------------- " '"' 
+3
source

Another option is to use an xpath extractor for this:

+1
source

Try the following regex:

 ItemID="(.+)" 
+1
source

Source: https://habr.com/ru/post/1444018/


All Articles