PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/HW_XML/Parsers/HW_XML_Parsers/06.ExtractSongsLINQ/ExtractSongs.cs

https://github.com/bankova/Databases
C# | 25 lines | 22 code | 2 blank | 1 comment | 0 complexity | 06b24820a4a4158577800de35de2c3f9 MD5 | raw file
  1. //Rewrite the same using XDocument and LINQ query.
  2. using System;
  3. using System.Xml;
  4. using System.Xml.Linq;
  5. using System.Linq;
  6. class ExtractSongs
  7. {
  8. static void Main()
  9. {
  10. XDocument xmlDoc = XDocument.Load("../../catalogue.xml");
  11. var songs =
  12. from song in xmlDoc.Descendants("song")
  13. select new
  14. {
  15. Title = song.Element("title").Value,
  16. };
  17. Console.WriteLine("Found {0} songs:", songs.Count());
  18. foreach (var song in songs)
  19. {
  20. Console.WriteLine("Song Title {0}", song.Title);
  21. }
  22. }
  23. }