Blog Stats
  • Posts - 35
  • Articles - 0
  • Comments - 3
  • Trackbacks - 2

 

Perform a Case-IN sensitive Search in .NET Using XPath

The following code shows to how to perform a case-sensitive search in .NET using XPath.

and contains is used as like operator in xpath.

XML File:
<?xml version="1.0" encoding="utf-8"?>
<USERS>
  <USER>
    <NAME>sharvan</NAME>
    <PASSWORD>dhaka</PASSWORD>
  </USER>
</USERS>

Code File:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" Debug="true" %>

<SCRIPT runat="server">
void Page_Load(object sender, System.EventArgs e)
{
    if(!Page.IsPostBack)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath("user.xml")); 
 XmlNodeList nodeList = xmlDoc.SelectNodes("Users/User[contains(translate(Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),translate('Sharvan', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]");
 Response.Write(nodeList.Count.ToString());
    }
}


1. Case of matching the beginning of some text.
miCommunities% LIKE where wildcard is at end

 Corresponding XPath expression predicate,
[ starts-with( Name , 'miCommunities')]

2. Case of matching within some text.
%miCommunities% LIKE where there is a wildcard at both ends

 Corresponding XPath expression predicate,
[ contains( Name , 'miCommunities')]

Feedback

No comments posted yet.


Post a comment





 

 

 

Copyright © Sharvan Dhaka