Solved

Case-insensitive XPath Expression

Posted on 2009-07-09
1
1,181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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