首页 > 解决方案 > 使用 xmllint --xpath 提取嵌套属性值

问题描述

我正在尝试使用 bash、xmllint 和 --xpath 从 xml 字符串 ($body) 中提取节点的属性。

 "$body" xmlint--xpath"///customfields/*[1]

返回:

  <"customfield displayname="Hourly Snapshot" key="karmaunits" datatype="NUMERIC">

在这种情况下,我只想返回“键”的值,“karmaunits”。我搜索但找不到这个确切的案例。

<wmp>
<name>KarmaUnits</name>
<workload name="KarmaUnits" type="kb"/>
<type>custom</type>
<description/>
<fileguid>xxxxxxx8-ab78-42ba-9db7-31febcc3d9ef</fileguid>
<interval>1800</interval>
<executioncmd/>
<variables>
</variables>
<customfields>
<customfield displayname="Hourly Snapshot" key="karmaunits" datatype="NUMERIC">0</customfield>
</customfields>
</wmp>

标签: xmlshellxpath

解决方案


推荐阅读