Link to home
Start Free TrialLog in
Avatar of Bytech India
Bytech India

asked on

I want to do searching on the basis of first and third character i.e. a*d using LINQ from an xml file.How should i do it?

Dear All

I have an XML file in which I am searching city's on the basis of filter containing first three characters,which is working fine.
 Locations = from data in doc.Root.Elements(rs + "data")
                                    // Get access to the child nodes using the XNamespace z
                                    from city in data.Elements(z + "row").Attributes("CITY")
                                    // Filter the result set
                                 where city.Value.StartsWith(substr)
                                    select city;
Now I want to do searching on the basis of only first and third character,second character can be anything.
How should I do it?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bytech India
Bytech India

ASKER

ohh it was too simple.Actually I have started looking using SQLMethod function and get lost somewhere else.
Thank you sir,I will try this.
Its working perfectly.Can I check two attributes too using same LINQ query i.e. state is Delhi and city starts with filter?If yes,please explain.
Thank you sir.
I did it as below and succeeded.

 IEnumerable<XElement> Region = from data in doc.Root.Elements(rs + "data")
                                               from el in data.Elements(z + "row")
                                               where el.Attribute("REGION_NAME").Value == State
                                               select el;

                Locations = from city in Region.Attributes("CITY")
                            where city.Value.StartsWith(Filter)
                            select city;