Saturday, 17 May 2014

How To Search Text On XML, Ignoring Case

Lets take example:
XML:
<Names>
<Name>Debasish</Name>
<Name>Subhasish</Name>
</Names>

What would be xpath to search Node with text "Debasish".
The xpath=//Name[contains(text(),'Debasish')].
The outcome=Element='<Name>Debasish</Name>'

Lets see the outcome when xpath=//Name[contains(text(),'debasish')].
There is no match. (I have used online tool http://www.freeformatter.com/).

Now, what can i do to search text irrespective of its case.
One general solution, we normally use in programming is to either convert text to lower case or upper case and then compare.
Here, in case of xpath, we will do same.
The xpath would be: //Name[contains(lower-case(text()),'debasish')]
The outcome=Element='<Name>Debasish</Name>'

No comments:

Post a Comment