xml - 使用 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>
解决方案
推荐阅读
- c++ - 在 C++ Graphics.h 中绘制圆弧
- c# - PersistKeysToAzureBlobStorage():.Net Framework 4.6/4.x 应用程序是否有等效方法?
- swift - 如何将类作为参数传递给 Swift 中的函数?
- php - Lumen API 选择按聚合分组的数据
- javascript - 当位置服务关闭时,在 iOS 上 navigator.gelocation 仍然为真
- javascript - 如何使用 Path2D(或任何形状抽屉)在 Java 中绘制 SVG 路径点?
- angular - 在另一个管道中注入 AsyncPipe
- google-cloud-platform - 子域未映射到 Google Cloud Compute Engine 中的负载平衡器后端服务
- angular - 没有路由的Angular 7组件重定向
- powershell - 与 Powershell IDE 相比,Powershell.exe 中的结果不同