Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 基于值的XMLStarlet返回属性(反向查找)_Xpath_Xquery_Xmlstarlet - Fatal编程技术网

Xpath 基于值的XMLStarlet返回属性(反向查找)

Xpath 基于值的XMLStarlet返回属性(反向查找),xpath,xquery,xmlstarlet,Xpath,Xquery,Xmlstarlet,我有以下xml: <block name="http-www.example.com"> <mapentry tag="AB12">bottlecap</mapentry> <mapentry tag="CD45">description goes here</mapentry> <mapentry tag="GH23">12345</mapentry> <mapentry tag="JK8

我有以下xml:

<block name="http-www.example.com">
  <mapentry tag="AB12">bottlecap</mapentry>
  <mapentry tag="CD45">description goes here</mapentry>
  <mapentry tag="GH23">12345</mapentry>
  <mapentry tag="JK89">54321</mapentry>
</block>

有没有办法搜索该值?

也许这就是您想要的

xmlstarlet sel -t -v "//mapentry[. = 'bottlecap']/@tag" "mytest.xml"

对非常感谢。我不知道这个[.='xx']语法。那太好了!
xmlstarlet sel -t -v "//mapentry[. = 'bottlecap']/@tag" "mytest.xml"