/HW_XML/Parsers/HW_XML_Parsers/06.ExtractSongsLINQ/ExtractSongs.cs
C# | 25 lines | 22 code | 2 blank | 1 comment | 0 complexity | 06b24820a4a4158577800de35de2c3f9 MD5 | raw file
- //Rewrite the same using XDocument and LINQ query.
- using System;
- using System.Xml;
- using System.Xml.Linq;
- using System.Linq;
- class ExtractSongs
- {
- static void Main()
- {
- XDocument xmlDoc = XDocument.Load("../../catalogue.xml");
- var songs =
- from song in xmlDoc.Descendants("song")
- select new
- {
- Title = song.Element("title").Value,
- };
- Console.WriteLine("Found {0} songs:", songs.Count());
- foreach (var song in songs)
- {
- Console.WriteLine("Song Title {0}", song.Title);
- }
- }
- }