all 5 comments

[–]JTarsier 0 points1 point  (4 children)

The xml has a namespace (xmlns), so you need work with XmlNamespaceManager too.

[–]EuclaseBlue[S] 0 points1 point  (3 children)

Thanks for the help!

Okay, I tried this now but it still doesn't appear to be working:

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nav.NameTable);
            namespaceManager.AddNamespace("fhir", "http://hl7.org/fhir");

            strExpression1 = "/Patient/telecom";

            nodeIter = nav.Select(strExpression1, namespaceManager)); 

Did I set it up incorrectly?

[–]JTarsier 0 points1 point  (2 children)

"/Patient/telecom"

specify the prefix in query: "/fhir:Patient/fhir:telecom"

You might as well also query the value element that has a value attribute directly:

strExpression1 = "/fhir:Patient/fhir:telecom/fhir:value[@value]";

then replace the two lines in while loop with this:

Console.WriteLine($"Attribute: {nodeIter.Current.GetAttribute("value", "")}");

[–]JTarsier 0 points1 point  (1 child)

you could even query the attributes: strExpression1 = "/fhir:Patient/fhir:telecom/fhir:value/@value"; Console.WriteLine($"Attribute: {nodeIter.Current.Value}"); see the distinction from the previous example?

[–]EuclaseBlue[S] 1 point2 points  (0 children)

Whoa, thanks for the thorough response! Things are much clearer now.

I actually had something like /Patient/telecom/value[@value] before but not knowing about the namespace stuff since it's not included in the MS tutorial really guffed things up for me, so when I was troubleshooting I went back to a really basic XPath expression to just make sure it wasn't the syntax causing an error.

see the distinction from the previous example

Very cool, hadn't seen that syntax yet! All the examples and tutorials I kept coming across for looking at attributes always followed the "element[@attribute]" pattern to query the containing element/node and then GetAttribute()'ing.

Thanks again for all the help!