powershell xml select attribute value where clause

后端 未结 2 893
清歌不尽
清歌不尽 2021-01-27 04:36

I have a xml file with the following elements:




        
相关标签:
2条回答
  • 2021-01-27 04:38

    The non-XPATH method:

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

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

    ($qrda.ClinicalDocument.recordTarget.patientRole.telecom | Where use -eq "HP").value
    
    0 讨论(0)
  • 2021-01-27 04:48

    Use XPath. Assuming that $qrda is your XML document:

    $path = "/ClinicalDocument/recordTarget/patientRole/telecom[@use='HP']"
    $telecom = $qrda.SelectSingleNode($path)
    

    since that path is pretty long and overly specific we can trim it down:

    $telecom = $qrda.SelectSingleNode("//telecom[@use='HP']")
    
    0 讨论(0)
提交回复
热议问题