예제 #1
0
        private bool NewspaperValidate(NewspaperLibraryElement element)
        {
            var extendedValidate = ExtendedValidate(element);

            if (string.IsNullOrEmpty(element.ISSN))
            {
                return(false);
            }
            else
            {
                return(extendedValidate);
            }
        }
예제 #2
0
        static void Write()
        {
            var root = new RootLibraryElement();

            var book = new BookLibraryElement();

            book.Name             = "TestBook";
            book.PageCount        = 34;
            book.PublicationPlace = "Karaganda";
            book.PublisherName    = "Fgfgf";
            book.PublishYear      = 1943;
            book.ISBN             = "5786v45677v76487";
            book.Comment          = "fgkllrlljjklghhgfdhfhgfhgf";
            book.Authors          = "Villain";

            root.Elements.Add(book);

            var paper = new NewspaperLibraryElement();

            paper.Name             = "TestPaper";
            paper.PageCount        = 25;
            paper.PublicationPlace = "Karaganda";
            paper.PublisherName    = "Namenaem";
            paper.PublishYear      = 2001;
            paper.ISSN             = "456754547687";
            paper.Comment          = "fgkоднакоhgf";
            paper.Date             = DateTime.Now;
            paper.Number           = 856;

            root.Elements.Add(paper);

            var patent = new PatentLibraryElement();

            patent.Name               = "TestPatent";
            patent.PageCount          = 125;
            patent.ApplicationDate    = DateTime.Now.Date.AddDays(-2);
            patent.PublicationDate    = DateTime.Now.Date.AddDays(-1);
            patent.Creator            = "Леша изобрел что-то там";
            patent.Country            = "Гваделупа";
            patent.Comment            = "вот какая она";
            patent.RegistrationNumber = 766456;

            root.Elements.Add(patent);

            var worker = new XMLWorker();

            worker.WriteToXMLFile(root, @"D:\XMLFileWriteTest.xml");

            Console.ReadKey();
        }
예제 #3
0
        public IEnumerable ReadXMLFromStream(Stream stream)
        {
            var reader = XmlReader.Create(stream);

            while (reader.ReadToFollowing("libraryElement"))
            {
                var element = XElement.ReadFrom(reader) as XElement;
                var type    = element.FirstAttribute.Value;

                switch (type)
                {
                case "book":

                    if (!BookXmlValidate(element))
                    {
                        break;
                    }

                    var book = new BookLibraryElement();
                    book.Name             = element.Element("name").Value;
                    book.Authors          = element.Element("authors").Value;
                    book.PublicationPlace = element.Element("city").Value;
                    book.PublisherName    = element.Element("publisher").Value;
                    book.PublishYear      = XmlConvert.ToInt32(element.Element("year").Value);
                    book.PageCount        = XmlConvert.ToInt32(element.Element("pageCount").Value);
                    book.Comment          = element.Element("comment").Value;
                    book.ISBN             = element.Element("ISBN").Value;

                    yield return(book);

                    break;

                case "newspaper":

                    if (!NewspaperXmlValidate(element))
                    {
                        break;
                    }

                    var newspaper = new NewspaperLibraryElement();
                    newspaper.Name             = element.Element("name").Value;
                    newspaper.Number           = XmlConvert.ToInt32(element.Element("number").Value);
                    newspaper.PublicationPlace = element.Element("city").Value;
                    newspaper.PublisherName    = element.Element("publisher").Value;
                    newspaper.PublishYear      = XmlConvert.ToInt32(element.Element("year").Value);
                    newspaper.PageCount        = XmlConvert.ToInt32(element.Element("pageCount").Value);
                    newspaper.Comment          = element.Element("comment").Value;
                    newspaper.ISSN             = element.Element("ISSN").Value;
                    newspaper.Date             = XmlConvert.ToDateTime(element.Element("date").Value, "yyyy-mm-dd");

                    yield return(newspaper);

                    break;

                case "patent":

                    if (!PatentXmlValidate(element))
                    {
                        break;
                    }

                    var patent = new PatentLibraryElement();
                    patent.Name               = element.Element("name").Value;
                    patent.Creator            = element.Element("creator").Value;
                    patent.Country            = element.Element("country").Value;
                    patent.RegistrationNumber = XmlConvert.ToInt32(element.Element("registrationNumber").Value);
                    patent.PageCount          = XmlConvert.ToInt32(element.Element("pageCount").Value);
                    patent.Comment            = element.Element("comment").Value;
                    patent.ApplicationDate    = XmlConvert.ToDateTime(element.Element("applicationDate").Value, "yyyy-mm-dd");
                    patent.PublicationDate    = XmlConvert.ToDateTime(element.Element("publicationDate").Value, "yyyy-mm-dd");

                    yield return(patent);

                    break;
                }
            }
        }