XPath for elements with attribute not equal or does not exist

后端 未结 1 749
不知归路
不知归路 2020-12-30 07:07

I have the following XML format:


 
     
     

        
                      
相关标签:
1条回答
  • 2020-12-30 07:44

    The "hard part" is actually easy: A basic

    element[not(@attribute= 'value')]

    predicate will exclude elements without the attribute and elements for which attribute equals value.

    So, in your specific case, all row elements that do not have @SubID equal to 1:

    /test/table/rows/row[not(@SubID = '1')]
    

    selects

    <row ID="1" Name="A"/>
    <row ID="3" Name="C"/>
    <row ID="5" Name="E"/>
    <row ID="4" Name="E" SubID="2"/>
    

    as requested.

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