Jmeter Regular Expression Extractor在xml中找到ItemID

时间:2012-11-05 00:21:37

标签: xml regex expression jmeter extractor

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

我正在尝试使用正则表达式从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>

我将Regular Expression Extractor设置如下:

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

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

我知道当我使用默认值设置为&#34; Col_001&#34;它工作正常。所以我的表达显然存在问题。

3 个答案:

答案 0 :(得分:3)

试试这个表达式:

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

解释

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

尝试以下正则表达式:

ItemID="(.+)"