Problem with linq-to-xml
- by phenevo
I want by linq save my xml in csv and I have o problem.
This bracket are here beacuse without it this code is not displaying (why ? )
bracket results bracket <Countries country="Albania"><Regions region="Centralna Albania"><Provinces province="Durres i okolice"><Cities city="Durres" cityCode="2B66E0ACFAEF78734E3AF1194BFA6F8DEC4C5760"><IndividualFlagsWithForObjects Status="1" /><IndividualFlagsWithForObjects Status="0" /><IndividualFlagsWithForObjects magazyn="2" /></Cities></Provinces></Regions></Countries><Countries ....
XDocument loaded = XDocument.Load(@"c:\citiesxml.xml");
// create a writer and open the file
TextWriter tw = new StreamWriter("c:\\XmltoCSV.txt");
// Query the data and write out a subset of contacts
var contacts = (from c in loaded.Descendants("Countries")
select new
{
Country = (string)c.Element("Country"),
Region = (string)c.Element("region"),
Province= (string)c.Element("province"),
City = (string)c.Element("city"),
Hotel = (string)c.Element("hotel")
}).ToList();
Problem is that loaded.Descendants("Countries") gives me 45 countries but all fields are null.