XPATH评估多个元素值



我的xml如下:

<Accounts>
   <Account>
    <AccountNumber>12345</AccountNumber>
    <Status>NEW</Status>
   </Account>
   <Account>
    <AccountNumber>12346</AccountNumber>
    <Status>NEW</Status>
  </Account>
  <Account>
   <AccountNumber>12347</AccountNumber>
   <Status>NEW</Status>
 </Account>
</Accounts>

我需要一个XPath来检查"状态"的所有元素值是否为"新",然后XPath表达式必须返回true,否则必须返回false。

我已经写了xpath'//*/status/text((='new''来实现它。但是,即使"状态"的价值除了'new''。

,这总是返回的。

您的XPath,

//*/Status/text() = 'NEW'' 

失败是因为它正在测试存在,而不是普遍性。

相反,根据您的要求的细节,使用以下内容之一:

  • 所有Account S必须具有Status,并且必须为<Status>NEW</Status>

    not(//Account[not(Status='NEW')])
    
  • 任何具有StatusAccount S都必须是<Status>NEW</Status>

    not(//Account[Status!='NEW'])
    

可能足以检查,如果有任何 <Status>text()与" new"不等于。这样的东西:

/Accounts/Account[Status/text()!="NEW"]

尝试以下操作: not(//Status[. != 'NEW''])

最新更新