/HW_XML/Parsers/HW_XML_Parsers/12.ExtractPricesLINQ/ExtractPricesLINQ.cs
C# | 31 lines | 27 code | 3 blank | 1 comment | 0 complexity | 9d3a7a4243bef3a3f9a6a8a8761aff33 MD5 | raw file
- //Rewrite the previous using LINQ query.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Linq;
- class ExtractPricesLINQ
- {
- static void Main()
- {
- XDocument xmlDoc = XDocument.Load("../../catalogue.xml");
- var albums =
- from album in xmlDoc.Descendants("album")
- where int.Parse(album.Element("year").Value)<2008
- select new
- {
- Title = album.Element("name").Value,
- Price = album.Element("price").Value
- };
- Console.WriteLine("Found {0} albums:", albums.Count());
- foreach (var album in albums)
- {
- Console.WriteLine(" Album Name {0}-> Price {1}.00 USD", album.Title, album.Price);
- }
- }
- }