xmlstarlet select value

前端 未结 1 1848
既然无缘
既然无缘 2020-12-13 21:31

This is the xml-data:


  
    
      
      

        
相关标签:
1条回答
  • 2020-12-13 21:43

    The key is to start from the ITEM node, not the identifyer:

    $ xmlstarlet sel -t -c "/DATA/TABLES/ITEM[identifyer/@V=1234]" test.xml
    <ITEM>
      <identifyer V="1234"/>
      <property1 V="abcde"/>
      <Property2 V="qwerty"/>
    </ITEM>
    

    Then you can pick out the bits you want:

    $ xmlstarlet sel -t -c "/DATA/TABLES/ITEM[identifyer/@V=1234]/*" test.xml
    <identifyer V="1234"/><property1 V="abcde"/><Property2 V="qwerty"/>
    
    $ xmlstarlet sel -t -v "/DATA/TABLES/ITEM[identifyer/@V=1234]/Property2/@V" test.xml
    qwerty
    
    0 讨论(0)
提交回复
热议问题