xml_grep从元素获取属性 [英] xml_grep get attribute from element
本文介绍了xml_grep从元素获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用xml_grep是否有可能(如果是,如何)从特定元素获取特定属性的值?我似乎只能在标签之间输出信息.
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 the information between tags.
示例:
<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>
从"identity"元素中输出"nationalnumber"属性的值(在本例中为13021912354)
output the value (in this case: 13021912354) of the 'nationalnumber'-attribute from the 'identity'-element
推荐答案
使用xmllint
:
xmllint --xpath 'string(//identity/@nationalnumber)' file.xml
对于debian发行版(或衍生版本),xmllint
是 libxml2-utils
软件包的一部分并可以这样安装:
For debian distro (or derivatives) xmllint
is part of the libxml2-utils
package and can be installed so:
apt-get install libxml2-utils
这篇关于xml_grep从元素获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文