How can I get the value from an attribute using xmllint and XPath?

后端 未结 4 1413
小鲜肉
小鲜肉 2020-12-08 13:23

I want to get the value of name and put it in a variable using XMLLint





echo \'cat //body         


        
4条回答
  •  独厮守ぢ
    2020-12-08 14:20

    Try this, it's not beautiful but it works :)

    I just erase lines containing > from stdout , cut the string to get the second part after the = , and delete "

    test=$(echo 'cat //body/value/@name' | xmllint --shell "test.xml" | grep -v ">" | cut -f 2 -d "=" | tr -d \"); 
    echo $test
    

提交回复
热议问题