1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
581 views
by rich-c-2789 (17.6k points)
I have an XML like this
<Message>
<Id>123</Id>
<CreatedDate>200607041522</CreatedDate>
<PatientData>
<Ids>
<Id>
<Type>LocalSystem</Type>
<Value>123456789</Value>
</Id>
<Id>
<Type>ExternalSystem</Type>
<Value>456123789</Value>
</Id>
</Ids>
</PatientData>
</Message>
Can I use X-path to get the value for the Id with a type of "LocalSystem" regardless of case?  I have seen messages with all of the following combinations:

o  LocalSystem

o  Localsystem

o  LOCALSYSTEM

o  localsystem

I tried
message.getNode('/Message/PatientData/Ids/Id[Type='NHS']/Value');
but it fails unless the case matches.

1 Answer

0 votes
Change the predicate from [Type='NHS'] to [upper-case(Type)='NHS']
message.getNode('/Message/PatientData/Ids/Id[upper-case(Type)='NHS']/Value');
The same goes when using node tags
{s:/Message/PatientData/Ids/Id[upper-case(Type)='NHS']/Value}
Note: Not all the XPath 2.0 functions are implemented in all XML parsers.  
 
Also see these references:
by rich-c-2789 (17.6k points)
...