Get pom.xml version with xmllint

前端 未结 1 891
梦毁少年i
梦毁少年i 2020-12-31 16:32

I have a pom.xml as such



        
相关标签:
1条回答
  • 2020-12-31 17:09

    Since your XML is using namespaces, there's no real nice way to do it. For a direct xpath query, if it's safe to ignore the namespace, you could do something like this:

    $ xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml
    

    If you wanted to do it the "right" way, you'll need to start a shell to setup the namespaces and output the desired value. Unfortunately, you'll have to clean out the prompts in the output.

    $ xmllint --shell pom.xml <<< 'setns ns=http://maven.apache.org/POM/4.0.0
    cat /ns:project/ns:version/text()'
    
    0 讨论(0)
提交回复
热议问题