Case-Insensitive XPath Searching

As far as I know, there is no such xpath function to do the case-insenstive search.
However, there is a work-around for this.
The solution is to receive a lower-case string as the input and use lower-case() xpath function to help perform the search.
Consider the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<specification>
  <name>ASUS Striker</name>
  <manufacturer>ASUS</manufacturer>
  <model>Striker</model>
</specification>

The following xpath do the search for “asu” which returns two string – “asus striker” and “asus”:

/specification//lower-case(text())[contains(.,'asu')]

As we can see, using lower-caes() and contains() helps search for lower-case string even though the xml contains upper-case string.
The text() function indicates the value of the node in context.
You can also try name() which indicates the name of the node.
You can try using upper-case() with upper-case input string as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>