Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public static void Main()
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load("../../xml/catalogue.xml");
            var root = xmlDocument.DocumentElement;
            IPrinter printer = new ConsolePrinter();

            PrintAlbumsCount(root, printer);
        }
Exemplo n.º 4
0
        public static void Main()
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load("../../xml/catalogue.xml");
            var root = xmlDocument.DocumentElement;

            IPrinter printer = new ConsolePrinter();

            string xPathQuery = "/albums/album/artist";

            PrintAlbumsCountWithXPath(xmlDocument, xPathQuery, printer);
        }
Exemplo n.º 5
0
        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!");
        }
Exemplo n.º 6
0
        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);
        }