Hi,
I have thousand of records in Xml file. I want to filter data just like as sql server "Like" operator. Is it possible on Xml File or not?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sunny SharmaRank #223 · 11.1K reputationPosted Sep 29, 2013, 11:36 PM EDT
please show me XMlL (sample) structure and what you want to do.
Gurjeet Singh107 reputationPosted Sep 29, 2013, 11:56 PM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 30, 2013, 12:22 AM EDT
I've added a root node to the file which now looks like this:
As expected, the output of the program is:
Sunny SharmaRank #223 · 11.1K reputationPosted Sep 30, 2013, 12:34 AM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Sep 30, 2013, 1:09 AM EDT
using System.IO;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Collections;
class Program
{
static void Main()
{
string xml = @"
using (StringReader stream = new StringReader(xml))
{
XPathDocument doc = new XPathDocument(stream);
XPathNavigator nav = doc.CreateNavigator();
// Compile a standard XPath expression
XPathExpression expr;
//If your Env is XPath 2.0 then use lower-case() instead of translate
expr = nav.Compile("/root/customer/lastname[contains(translate(text(),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'SMITH')] | /root/customer/firstname[contains(translate(text(),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'SMITH')] ");
XPathNodeIterator iterator = nav.Select(expr);
try
{
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
Console.WriteLine("Found: " + nav2.Value);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}