1

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

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.

Any help is much appreciated.

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

The short form, ($qrda.ClinicalDocument.recordTarget.patientRole.telecom | Where use -eq "HP") should also be possible.
@Tomalak Thanks - tested, it worked, added to answer.
1

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']")

2 Comments

This did not work for me. But seeing as how my xml doc is from the government, it's not surprising.
That has nothing to do with the government and everything with your question not showing the XML file itself. My answer is a best guess under these circumstances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.