powershell xml选择属性值where子句 [英] powershell xml select attribute value where clause

查看:59
本文介绍了powershell xml选择属性值where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下元素的 xml 文件:

I have a xml file with the following elements:

<telecom use="HP" value="tel:+1-512-555-1212" />
<telecom use="WP" value="tel:+1-512-123-4567" />

这将返回第一个节点的值:

this returns the value of the first node:

$qrda.ClinicalDocument.recordTarget.patientRole.telecom[0].value

但是,我需要能够返回 use="HP" 的节点,而且我不确定它们的顺序是否总是正确的.

However I need to be able to return the node where use="HP" and I'm not certain they'll always be in the correct order.

非常感谢任何帮助.

推荐答案

非 XPATH 方法:

The non-XPATH method:

($qrda.ClinicalDocument.recordTarget.patientRole.telecom | Where {$_.use -eq "HP"}).value

或者(感谢 Tomalak 的有用评论),使用 比较语句格式:

Or (thanks to Tomalak's helpful comment), using the comparison statement format:

($qrda.ClinicalDocument.recordTarget.patientRole.telecom | Where use -eq "HP").value

这篇关于powershell xml选择属性值where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆