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

/HW_XML/Parsers/HW_XML_Parsers/12.ExtractPricesLINQ/ExtractPricesLINQ.cs

https://github.com/bankova/Databases
C# | 31 lines | 27 code | 3 blank | 1 comment | 0 complexity | 9d3a7a4243bef3a3f9a6a8a8761aff33 MD5 | raw file
  1. //Rewrite the previous using LINQ query.
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using System.Xml.Linq;
  9. class ExtractPricesLINQ
  10. {
  11. static void Main()
  12. {
  13. XDocument xmlDoc = XDocument.Load("../../catalogue.xml");
  14. var albums =
  15. from album in xmlDoc.Descendants("album")
  16. where int.Parse(album.Element("year").Value)<2008
  17. select new
  18. {
  19. Title = album.Element("name").Value,
  20. Price = album.Element("price").Value
  21. };
  22. Console.WriteLine("Found {0} albums:", albums.Count());
  23. foreach (var album in albums)
  24. {
  25. Console.WriteLine(" Album Name {0}-> Price {1}.00 USD", album.Title, album.Price);
  26. }
  27. }
  28. }