Solved

Case-insensitive XPath Expression

Posted on 2009-07-09
1
1,157 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now