Geeks With Blogs
Tim Huffam Dotting the I and crossing the T of I.T.

XPath statements are case sensitive.  To get around this use the following example to convert all data to lower case before performing the equality check:

/bookstore/book[translate(@category, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + searchtext.ToLower() + "']

Thanks very much to Harish for this!

Posted on Thursday, July 6, 2006 11:01 AM | Back to top


Comments on this post: Case insensitive XPath

# re: Case insensitive XPath
Requesting Gravatar...
thanks nice work around!
Left by kbird on Jun 19, 2007 5:52 AM

# re: Case insensitive XPath
Requesting Gravatar...
Hi,

I am getting an XPAth expression an an input from a text box as a string and then using the string to make an XPAth search. How can I use this tranlate func() there to make my search case insensitive. I am working in C# .Net.
Left by Anoop on Sep 21, 2007 1:26 AM

# re: Case insensitive XPath
Requesting Gravatar...
Thank you, just what I was looking for!
Left by Jawad on Aug 12, 2009 2:01 PM

# re: Case insensitive XPath
Requesting Gravatar...
Thanks, exactly what I was looking for! =D
Left by Alan Feekery on Mar 26, 2010 11:22 AM

# re: Case insensitive XPath
Requesting Gravatar...
worked great
Left by Siva on Apr 30, 2010 1:31 PM

# re: Case insensitive XPath
Requesting Gravatar...
Thanks Tim, worked well.
Left by yrami on Jun 09, 2010 9:11 AM

# re: Case insensitive XPath
Requesting Gravatar...
<?xml version="1.0"?>
<!-- This file represents a fragment of a bookstore inventory database -->
<bookstore specialty="novel">
<book>
<Title>Beginning XML</Title>
<Publisher>Wrox</Publisher>
</book>
<book>
<Title>Professional XML</Title>
<Publisher>Wrox</Publisher>
</book>
<book>
<Title>Programming ADO</Title>
<author>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
</author>
<datePublished>1/1/2000</datePublished>
<Publisher>Microsoft Press</Publisher>
</book>
</bookstore>

This xpath converts the title to lower case and searches for 'xml' in the Title element and returns all the book Nodes for that title

/bookstore/book/Title[lower-case(.)[contains(.,'xml')]]

Left by vk on Sep 23, 2010 11:08 AM

# re: Case insensitive XPath
Requesting Gravatar...
Thanks vk, I was getting problems with retrieving nodesets and converting them to upper-case for string comparison, which you obviously can't do.
Your workaround gets round it by converting each node's value within the [] brackets and so I can evaluate my string inside there.
Regards
Imty
Left by TheHacker on Sep 29, 2010 3:29 AM

# re: Case insensitive XPath
Requesting Gravatar...
Great work, thank you for that.
Left by Aaron on Jun 29, 2011 12:12 AM

# re: Case insensitive XPath
Requesting Gravatar...
I really loved reading your blog. It was very well authored and easy to understand. Unlike additional blogs I have read which are really not good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he enjoyed it as well!
Left by vietnam Train Service on Dec 17, 2011 4:15 AM

# re: Case insensitive XPath
Requesting Gravatar...
Thank you for sharing this article, I will do as instructed. Expect to succeed
Left by Vietnam Railways on Apr 09, 2012 10:17 PM

Your comment:
 (will show your gravatar)


Copyright © Tim Huffam | Powered by: GeeksWithBlogs.net | Join free