首页 文章

用于评估多个元素值的xpath

提问于
浏览
0

我有一个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来检查'Status'的所有元素值是否为'NEW',然后xpath表达式必须返回true,否则它必须返回false .

我写了一个xpath'// * / Status / text()='NEW'来实现它 . 但即使“状态”的值不是“新”,这也会一直返回 .

3 回答

  • 0

    你的XPath,

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

    失败是因为它在考验存在,而不是普遍性 .

    而是根据您的要求的具体情况使用以下之一:

    • 所有 Account 必须有 Status 且必须是 <Status>NEW</Status>
    not(//Account[not(Status='NEW')])
    
    • 任何有 StatusAccount 必须是 <Status>NEW</Status>
    not(//Account[Status!='NEW'])
    
  • 2

    试试这个: not(//Status[. != 'NEW''])

  • 0

    如果 text()not equal 到"NEW",那么检查可能就足够了 . 像这样的东西:

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

相关问题