Jmeter Regular Expression Extractor在xml中找到ItemID

时间:2021-08-13 13:00:40

I am new to ; I hope that I can describe my problem to you well enough.

我是jmeter的新手;我希望我能够很好地向你描述我的问题。

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

我试图使用正则表达式从xml元素中提取ItemID属性。然后我在另一个请求中使用它。这是我试图从中提取ItemID的XML响应:

<?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 the Regular Expression Extractor set up as follows:

我有正则表达式提取器设置如下:

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

In the 2nd request I have set the ItemID as follows ... ItemID=${item} ...

在第二个请求中,我将ItemID设置如下... ItemID = $ {item} ...

I know that When I use the Default Value set to "Col_001" it works fine. So there is obviously a problem with my Expression.

我知道当我使用设置为“Col_001”的默认值时,它可以正常工作。所以我的表情显然有问题。

3 个解决方案

#1


3  

Try this 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
--------------------------------------------------------------------------------
  "                        '"'

#2


1  

Another option is to use xpath extractor to do this:

另一种选择是使用xpath提取器来执行此操作:

#3


1  

Try the following regex:

试试以下正则表达式:

ItemID="(.+)"

#1


3  

Try this 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
--------------------------------------------------------------------------------
  "                        '"'

#2


1  

Another option is to use xpath extractor to do this:

另一种选择是使用xpath提取器来执行此操作:

#3


1  

Try the following regex:

试试以下正则表达式:

ItemID="(.+)"