2012-11-05 76 views
4

我是;我希望我能夠很好地向你描述我的問題。Jmeter正則表達式提取器找到xml中的ItemID

我想用正則表達式從xml元素中提取ItemID屬性。然後我在另一個請求中使用它。這是我想從提取項目ID的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> 

我也正則表達式提取設置如下:

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

在我已經設置了項目ID如下的第二請求... ItemID = $ {item} ...

我知道,當我使用默認值設置爲「Col_001」它工作正常。所以我的表情顯然有一個問題。

回答

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

請嘗試以下正則表達式:

ItemID="(.+)" 
相關問題