PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/HW_XML/Parsers/HW_XML_Parsers/04.DeleteAlbums/DeleteAlbums.cs

https://github.com/bankova/Databases
C# | 35 lines | 28 code | 5 blank | 2 comment | 1 complexity | 979f35ed820a92a56f80c925948a57b8 MD5 | raw file
  1. //Using the DOM parser write a program to delete from catalog.xml
  2. //all albums having price > 20.
  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 DeleteAlbums
  10. {
  11. class DeletAlbums
  12. {
  13. static void Main()
  14. {
  15. XmlDocument doc = new XmlDocument();
  16. doc.Load("../../catalogue.xml");
  17. foreach (XmlNode node in doc.DocumentElement)
  18. {
  19. if (decimal.Parse(node["price"].InnerText) > 20)
  20. {
  21. XmlNode parent = node.ParentNode;
  22. parent.RemoveChild(node);
  23. }
  24. }
  25. Console.WriteLine("Modified XML document:");
  26. Console.WriteLine(doc.OuterXml);
  27. doc.Save("../../catalogueNEW.xml");
  28. }
  29. }
  30. }