XPATH Multiple Element Filters

后端 未结 3 385
北海茫月
北海茫月 2020-12-07 21:27

I have the following sample XML structure:


    
       yes
       <         


        
相关标签:
3条回答
  • 2020-12-07 21:49
    /SavingAccounts/SavingAccount[(ServiceOnLine='yes') or (ServiceViaPhone='yes')]
    
    0 讨论(0)
  • 2020-12-07 22:02

    This is a very fundamental XPath feature: composing a number of conditions with the logical operators and, or, and the function not().

    and has a higher priority than or and both operators have lower priority than the relational and equality operators (=, !=, >, >=, &lt; and &lt;=).

    So, it is safe to write: A = B and C = D

    Some most frequent mistakes made:

    1. People write AND and/or OR. Remember, XPath is case-sensitive.

    2. People use the | (union) operator instead of or

    Lastly, here is my solution:

    /SavingAccounts/SavingAccount
               [ServiceOnLine='yes' or ServiceViaPhone='yes']
    

    0 讨论(0)
  • 2020-12-07 22:07

    Will

    /SavingAccounts/SavingAccount[ServiceOnline/text()='yes' or ServiceViaPhone/text()='yes']
    

    do the trick?

    I have no XPath evaluator handy at the moment.

    EDIT:
    If I remember correctly, you don't need the text(), so

    [ServiceOnline='yes' or ServiceViaPhone='yes']
    

    should be sufficient, and more readable.

    EDIT:
    Yes, of course, 'or' for predicate expressions, my bad.

    0 讨论(0)
提交回复
热议问题