I am trying to read a complex XML file using LinQ.
The XML file has a lot of levels, how can get all value in one ILIST<> . there are more tags in items.enter code here
The XML has the following syntax:
<root> <items> <index_0> <product_id>19</product_id> <menu_rank>2</menu_rank> <menu_country>Guatemala</menu_country> <menu_country_code>502</menu_country_code> <menu_country_abrv>GT</menu_country_abrv> <menu_carrier>TIGO</menu_carrier> <menu_value>7.0</menu_value> </index_0> <index_1> <product_id>20</product_id> <menu_rank>2</menu_rank> <menu_country>Guatemala</menu_country> <menu_country_code>502</menu_country_code> <menu_country_abrv>GT</menu_country_abrv> <menu_carrier>TIGO</menu_carrier> <menu_value>10.0</menu_value> </index_1> <index_2> <product_id>21</product_id> <menu_rank>2</menu_rank> <menu_country>Guatemala</menu_country> <menu_country_code>502</menu_country_code> <menu_country_abrv>GT</menu_country_abrv> <menu_carrier>TIGO</menu_carrier> <menu_value>14.0</menu_value> </index_2> </items> </root> I have tried this approach but without success :
var chartrate = from a in xmlDoc.Descendants("items") select new { sub_id = a.Element("product_id").Value, product = a.Element("menu_rank").Value, description = a.Element("menu_country").Value } ; Any suggestions?
index_0,index_1, ...) is going to cause you problems. Change it to something like<item index="0">if you can.