Xml_grep get attribute from element
Is it possible (and if so, how) with xml_grep to get the value of a specific attribute from a specific element? I only seem to be able to output information between tags.
Example:
<eid>
<identity nationalnumber="13021912354" dateofbirth="20130219" gender="male">
<name>Menten</name>
<firstname>Kasper</firstname>
<middlenames>Marie J</middlenames>
<nationality>Belg</nationality>
<placeofbirth>Sint-Truiden</placeofbirth>
<photo>base64-string</photo>
</identity>
</eid>
outputs the value (in this case: 13021912354) of the "nationalnumber" attribute from the "identity" element
+3
source to share
2 answers
From xmllint
:
xmllint --xpath 'string(//identity/@nationalnumber)' file.xml
For debian, distro (or derivatives) xmllint
is part of the package libxml2-utils
and can be installed like this:
apt-get install libxml2-utils
+5
source to share