Extracting and dumping elements using xmlstarlet

前端 未结 1 376
悲&欢浪女
悲&欢浪女 2020-12-05 11:34

I am looking for a way to extract and print an element from my xml using xmlstarlet; for example if my xml is



        
1条回答
  •  执念已碎
    2020-12-05 12:09

    Using the "-c" (copy) option, should achieve what you're after:

    xmlstarlet sel -t -c "/bookstore/book[price=29.99]" books.xml
    
    
      Harry Potter
      29.99
    
    

    You can watch the XSLT generated internally in xmlstarlet by adding the global "-C" switch after "sel". This shows how the copy option results in an xslt copy-of construct:

    ...
    
      
    
    ...
    

    This results in namespace nodes, child nodes, and attributes nodes being included, cf. the XSLT spec (see w3schools summary).

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