How to parse a XML file using Linq - descendants

carlbenz

New Member
I am having trouble using \[code\]XDocument\[/code\] Linq-to-XML in C# to parse the following XML:\[code\]<matches count="9"><books count="4"> <book> <key>books/batman_dark_knight_returns/frank_miller</key> <title>Batman: The Dark Knight Returns</title> </book> ...</books><movies count="4"> <movie> <key>movies/batman_tales_of_dark_knight/boy_kirklan</key> <title>Batman: Tales of the Dark Knight</title> </movie> ...</movies><music count="1"> <album> <key>music/dark_knight/hans_zimmer</key> <title>The Dark Knight</title> </album></music> </matches>\[/code\]A snippet of my very very wrong code is \[code\]var data = http://stackoverflow.com/questions/11335056/from query in xmlFeed.Descendants("books") select new Book { Title = (string)query.Element("book").Element("title"), count = (string)query.Element("stickers").Element("sticker").Element("count") };searchListBox.ItemsSource = data;\[/code\]Any help on how I can parse a xml like this that returns books, movies, tv shows in a long list that I can bind to a list box?Thanks
 
Back
Top