Solved

Case-insensitive XPath Expression

Posted on 2009-07-09
1
1,170 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing information on Duplicate XML Nodes 24 83
Issue with XSLT mapping 10 48
JSON  parse help 8 52
Help with a Python script converting xml to csv 4 42
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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 …

749 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