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

Viewed 64167

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

<body>
<value name="abc"></value>
</body>

echo 'cat //body/value/@name' | xmllint --shell "test.xml"

/ >  -------
 name="abc"
/ > 

So I want to assign the value "abc" to variable $test

5 Answers

With the goal of matching multiple lines and extract the value of their homonymous attribute and building on previous answers this worked for me and it's shorter hehe

xmllint --xpath "//*/@value" file.xml | awk -F\" '{ print $2 }'
Related