public void Write(XmlWriter xmlWriter, ICatalogItem item) { Patent patent = item as Patent; if (patent == null) { throw new WriteException($"For {item.GetType().Name}, no writing format is defined"); } XMLUtilite.CheckFields(patent); XElement xPatent = new XElement("patent", new XElement("name", patent.Name), new XElement("authors", patent.Author?.Select(a => new XElement("name", a.Name))), new XElement("country", patent.Country), new XElement("registrationNamber", patent.RegistrationNamber), new XElement("filingDate", patent.FilingDate.Value.ToString("yyyy-MM-dd")), new XElement("publicationDate", patent.PublicationDate.Value.ToString("yyyy-MM-dd")), new XElement("pageCount", patent.PageCount), new XElement("remark", patent.Remark)); xPatent.WriteTo(xmlWriter); }
public ICatalogItem ParseFrom(XElement element) { if (element.Name == "patent") { Patent patent = new Patent() { Name = element.Element("name").Value, Author = element.Element("authors").Elements("name").Select(a => new Author { Name = a.Value }).ToList(), Country = element.Element("country").Value, RegistrationNamber = element.Element("registrationNamber").Value, PageCount = XMLUtilite.ConvertToInt((element.Element("pageCount").Value)), FilingDate = XMLUtilite.ConvertToDateTime(element.Element("filingDate").Value), PublicationDate = XMLUtilite.ConvertToDateTime(element.Element("publicationDate").Value), Remark = element.Element("remark").Value }; XMLUtilite.CheckFields(patent); return(patent); } throw new ParseException($"Element {element.Name} is unknown to the parser"); }
public ICatalogItem ParseFrom(XElement element) { if (element.Name == "book") { Book book = new Book() { Name = element.Element("name").Value, Author = element.Element("authors").Elements().Select(a => new Author { Name = a.Value }).ToList(), PublicationPlace = element.Element("publicationPlace").Value, PublisherName = element.Element("publisherName").Value, PublicationYear = XMLUtilite.ConvertToInt(element.Element("publicationYear").Value), PageCount = XMLUtilite.ConvertToInt(element.Element("pageCount").Value), Remark = element.Element("remark").Value, ISBN = element.Element("isbn").Value }; XMLUtilite.CheckFields(book); return(book); } throw new ParseException($"Element {element.Name} is unknown to the parser"); }
public void Write(XmlWriter xmlWriter, ICatalogItem item) { Newspaper newspaper = item as Newspaper; if (newspaper == null) { throw new WriteException($"For {item.GetType().Name}, no writing format is defined"); } XMLUtilite.CheckFields(newspaper); XElement xNewspaper = new XElement("newspaper", new XElement("name", newspaper.Name), new XElement("publicationPlace", newspaper.PublicationPlace), new XElement("publisherName", newspaper.PublisherName), new XElement("publicationYear", newspaper.PublicationYear), new XElement("pageCount", newspaper.PageCount), new XElement("remark", newspaper.Remark), new XElement("number", newspaper.Number), new XElement("date", newspaper.Date.Value.ToString("yyyy-MM-dd")), new XElement("issn", newspaper.ISSN)); xNewspaper.WriteTo(xmlWriter); }
public void Write(XmlWriter xmlWriter, ICatalogItem item) { Book book = item as Book; if (book == null) { throw new WriteException($"For {item.GetType().Name}, no writing format is defined"); } XMLUtilite.CheckFields(book); XElement xBook = new XElement("book", new XElement("name", book.Name), new XElement("authors", book.Author?.Select(a => new XElement("name", a.Name))), new XElement("publicationPlace", book.PublicationPlace), new XElement("publisherName", book.PublisherName), new XElement("publicationYear", book.PublicationYear), new XElement("pageCount", book.PageCount), new XElement("remark", book.Remark), new XElement("isbn", book.ISBN)); xBook.WriteTo(xmlWriter); }
public ICatalogItem ParseFrom(XElement element) { if (element.Name == "newspaper") { Newspaper newspaper = new Newspaper() { Name = element.Element("name").Value, PublicationPlace = element.Element("publicationPlace").Value, PublisherName = element.Element("publisherName").Value, PublicationYear = XMLUtilite.ConvertToInt(element.Element("publicationYear").Value), PageCount = XMLUtilite.ConvertToInt(element.Element("pageCount").Value), Remark = element.Element("remark").Value, ISSN = element.Element("issn").Value, Date = XMLUtilite.ConvertToDateTime((element.Element("date").Value)), Number = element.Element("number").Value }; XMLUtilite.CheckFields(newspaper); return(newspaper); } throw new ParseException($"Element {element.Name} is unknown to the parser"); }