Click here to Skip to main content
15,792,382 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
i have an xml file.

<?xml version="1.0" encoding="utf-8" ?>
   <feature id = "1" name = "car">
     <propery id = "1" name = "Model Number"/>
     <property id = "2" name = "Color of car"/>
   <feature id = "2" name = "Bike">
      <property id = "1" name = "Model of bike"/>
      <property id ="2" name = "Compnay name"/>

i want to search name of property element where feature name = car.

var Parameteroffeature = from xp in xelement.Elements("property")
                                   select xp.Attributes("name").Where()

please anyone help me.


Try this code..

I have used lamda expression instead of comprehension queries.

XDocument xdoc = XDocument.Load("xmlfile.xml");

           var lv1ss = xdoc.Descendants("Vehicle").Descendants("feature").Select(k => new
               propertyid = k.Descendants("propery").Select(a => new
                       propertyid = a.Attribute("id").Value,
                       propertyname = a.Attribute("name").Value
               id = k.Attribute("id").Value,
               name = k.Attribute("name").Value
           }).Where(k => == "car").ToList();
Share this answer
Share this answer
Share this answer
Rajeev Jayaram 4-Dec-13 7:16am    
None of the above links refer to any 'LINQ to XML' queries.
I suggest you to refer:
abbaspirmoradi 4-Dec-13 7:22am    
thanks,you right.
Rajeev Jayaram 4-Dec-13 8:04am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900