Solved

Case-insensitive XPath Expression

Posted on 2009-07-09
1
1,164 Views
Last Modified: 2013-11-11
If my xml file structure is like this:
<file>
      <entry>
            <name>
            <count>
      </entry>
      <entry>
            <name>
            <count>
      </entry>
      ...
</file>

Then, the following xpath expression is to get the 'count' for the matched name with user inputted name.
Here's inputname is a variable which I 'll get input from the user. Right?

XPathExpression expr = xpath
      .compile("//file/entry[name='" + inputname + "']//count/text()");
      
But it is case-sensitive, i mean if the user input is "Car" and if the name is "car". It cannot match because it is case-sensitive.
So, what I would like to know is .. can I tell xpathexpression not to be case-sensitive.
Is there anyway?

Thanks!!
0
Comment
Question by:Juuno
1 Comment
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24820548
you can make sure that input names is lower-case all the time, by lowercasing it prior to passing it to the XPath
you can lowercase name
in XPath 2 by using lower-case()
XPathExpression expr = xpath
      .compile("//file/entry[lower-case(name)='" + inputname + "']//count/text()");

in XPath 1 by using translate(), which is a bit clumsy
XPathExpression expr = xpath
      .compile("//file/entry[translate(name, 'AZERTYUIOPQSDFGHJKLMWXCVBN', 'azertyuiopqsdfghjklmwxcvbn')='" + inputname + "']//count/text()");

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question