xmlstarlet XPath expression selects single result rather than multiple

前端 未结 2 2009
天命终不由人
天命终不由人 2021-01-23 03:03

I have an XML file having structure like this:



    
        

        
2条回答
  •  醉酒成梦
    2021-01-23 03:36

    if you are not bound to xmlstarlet try to use xmllint otherwise adjustment of the xpath like shown below could help.

    $ xmllint --xpath '//role//sid/../../@name' roles.xml
     name="Employees" name="Others"
    

    The xml file for this example looked like

    
    
      
        
          
            
              abc
              bcd
            
          
          
            
              abc
              zxc
            
          
        
      
    
    

    In short you can address parent childs attribute by addressing them with ../@*.

提交回复
热议问题