JMeter Xpath2 extractor id 匹配多个条件

JMeter Xpath2 extractor id's matching multiple conditions

下面是示例 XML 片段,我试图从中筛选出符合以下两个条件的文章的 ID。目前我可以在下面的表达式

的帮助下为个别情况提取 id
  1. 获取可用文章,Xpath2 表达式 = (//*//*//*//*[starts-with(state,'Avaialable')])/id
  2. 获取以'A'()开头的文章名称,Xpath2表达式=(//*//*//*//*[starts-with(name,'A')])/id

我想将这些条件合并到一个表达式中,并且想要

fetch id's of Articles where Name starts with 'A' AND articles which are Available

。尝试了多种方法,但没有按预期工作。

虚拟 XML 片段:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:GetArtclesResponse
    xmlns:ns2="XXX"
    xmlns:ns4="XXX"
    xmlns:ns3="XXX"
    xmlns:ns6="XXX"
    xmlns:ns5="XXX"
    xmlns:ns8="XXX"
    xmlns:ns7="XXX"
    xmlns:ns13="XXX"
    xmlns:ns9="XXX"
    xmlns:ns12="XXX"
    xmlns:ns11="XXX">
    <serverTimeInfo timezone="+00:00" timestamp="1606409365419"/>
    <items>
        <count>2</count>
        <articles>
           <article>
                <name>ABC</name>
                <id>1234</id>
                <state>Avaialable</state>
            </article>
            <article>
                <name>XYZ</name>
                <id>3456</id>
                <state>Avaialable_Conditional</state>
            </article>
        </articles>
    </items>
</ns3:GetArtclesResponse>

您可以使用 and 检查两者:

(//*//*//*//*[starts-with(state,'Avaialable') and starts-with(name,'A')])/id
  1. 如果您想组合 2 个不同的 XPath 表达式,您可以使用 | (union) operator,例如:

     //article[state = 'Avaialable']  |  //article[starts-with(name,'A')]
    

    它将 return 你们俩:

    • 状态=可用的节点
    • 以及名字以A开头的节点
  2. 如果您想在单个 XPath 表达式中组合 2 个条件 - 请使用 and 运算符,例如:

    //article[state = 'Avaialable' and starts-with(name,'A')]
    

    会return

    • 状态为可用且名称属性以
    • 开头的节点

更多信息: