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

/HW_XML/Parsers/HW_XML_Parsers/11.ExtractPriceAlbums/ExtractPrice.cs

https://github.com/bankova/Databases
C# | 31 lines | 25 code | 4 blank | 2 comment | 0 complexity | e3eb11d7b6d7e01ea638abd6a30fab12 MD5 | raw file
  1. //Write a program, which extract from the file catalog.xml the prices
  2. //for all albums, published 5 years ago or earlier. Use XPath query.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9. namespace ExtractPriceAlbums
  10. {
  11. class ExtractPrice
  12. {
  13. static void Main()
  14. {
  15. XmlDocument xmlDoc = new XmlDocument();
  16. xmlDoc.Load("../../catalogue.xml");
  17. string xPathQuery = "/catalogue/album[year<2008]";
  18. XmlNodeList priceList = xmlDoc.SelectNodes(xPathQuery);
  19. foreach (XmlNode priceNode in priceList)
  20. {
  21. string albumName = priceNode.SelectSingleNode("name").InnerText;
  22. string price = priceNode.SelectSingleNode("price").InnerText;
  23. Console.WriteLine("Price of {0}-> {1}.00 USD", albumName, price);
  24. }
  25. }
  26. }
  27. }