在 XPath 中选择相反的条件?

Selecting the opposite condition in XPath?

我有以下XML

<Root>
    <Element>
        <batch_id>Jan_22_2021_18</batch_id>
        <proposal_id>130994</proposal_id>
        <proposal_name>Brazil </proposal_name>
        <subregion>1234</subregion>
        <currency>BRL</currency>
    </Element>
    <Element>
        <batch_id>Jan_22_2021_18</batch_id>
        <proposal_id>130994</proposal_id>
        <proposal_name>Brazil </proposal_name>
        <subregion>7225</subregion>
        <currency>BRL</currency>
    </Element>
        <Element>
        <batch_id>Jan_22_2021_18</batch_id>
        <proposal_id>130994</proposal_id>
        <proposal_name>Brazil </proposal_name>
        <subregion>1111</subregion>
        <currency>BRL</currency>
    </Element>
</Root>

低于 XPaths

  1. 工作:

    /Root/Element[(subregion ='7515') or (subregion ='7225') or (subregion ='1234') or (subregion ='8360') or (subregion ='8385') or (subregion ='8435') or (subregion ='8585')]
    
  2. 不工作

    /Root/Element[(subregion !='7515') or (subregion !='7225') or (subregion !='1234') or (subregion !='8360') or (subregion !='8385') or (subregion !='8435') or (subregion !='8585')]
    

你能解释一下为什么吗?

你逻辑有问题。

A or B的反义词是不是not(A) or not(B);它是 not(A or B),或者相当于 De Morgannot(A) and not(B)

因此,如果您想要其他 Elements – 未被您的“工作”XPath 选择的那些 – 对整个析取应用逻辑 not()

/Root/Element[not((subregion ='7515') 
               or (subregion ='7225') 
               or (subregion ='1234') 
               or (subregion ='8360') 
               or (subregion ='8385') 
               or (subregion ='8435') 
               or (subregion ='8585'))]

或对应连词的个别条件:

/Root/Element[    not(subregion ='7515') 
              and not(subregion ='7225') 
              and not(subregion ='1234') 
              and not(subregion ='8360') 
              and not(subregion ='8385') 
              and not(subregion ='8435') 
              and not(subregion ='8585')]