Sidebar

How to define case-insensitive XPath in getNode?

0 votes
276 views
asked Mar 10, 2016 by rich-c-2789 (15,190 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:
answered Mar 10, 2016 by rich-c-2789 (15,190 points)
...