public static void Main() { XmlSchemaSet schemas = new XmlSchemaSet(); schemas.Add("urn:catalogue", "..//..//xml/catalogue.xsd"); XDocument XmlDocument = XDocument.Load("..//..//xml/catalogue.xml"); List<string> errorMessages = new List<string>(); XmlDocument.Validate(schemas, (obj, error) => { errorMessages.Add(error.Message); }); IPrinter printer = new ConsolePrinter(); if (errorMessages.Count == 0) { printer.Print("Valid catalogue.xml"); } else { printer.Print(errorMessages); } }
public static void Main() { XmlReader reader = XmlReader.Create("../../xml/catalogue.xml"); List<string> songTitles = new List<string>(); var element = string.Empty; using (reader) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "song") { element = "song"; continue; } if (element == "song" && reader.NodeType == XmlNodeType.Text) { songTitles.Add(reader.Value); element = string.Empty; } } } IPrinter printer = new ConsolePrinter(); printer.Print(songTitles); }
public static void Main() { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("../../xml/catalogue.xml"); var root = xmlDocument.DocumentElement; IPrinter printer = new ConsolePrinter(); int price = 20; DeleteByPrice(xmlDocument, price); xmlDocument.Save("../../xml/catalogueResultxml"); printer.Print("Delete succsess!"); }
public static void Main() { XDocument xmlDocument = XDocument.Load("../../xml/catalogue.xml"); var songs = from album in xmlDocument.Descendants("album") select album.Element("songs"); var titles = from song in songs.Descendants("song") select song.Element("title").Value; IPrinter printer = new ConsolePrinter(); printer.Print(titles); }