Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am trying to write query for reading xml.

i have an xml in below format.

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



i want to read feature element with attribute name.

XElement xeelement = XElement.Load(@"F:\vehicleinfo_info.xml");

var loadfeature = from xe in xeelement.Elements("vehicle")
select xe.Element("feature").Attribute("name").Value;

i used this query but can read only one feature element with name attribute but getting only car i want car and bike both.

could anyone help me

thanks
Posted
Updated 9-Dec-13 3:12am
v3

http://www.codeproject.com/Forums/1649/Csharp.aspx?select=4715748&tid=4715143[^]

Gave an example to read XML files in this thread, maybe that helps you :)
 
Share this answer
 
You need to use .Elements rather than .Element..Have a look at http://msdn.microsoft.com/en-us/library/bb348975(v=vs.110).aspx[^]..
 
Share this answer
 

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