Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book
- {
- // Book variables
- string title, subtitle, author;
- int id, part, pages;
- // Adds a new book to the memory stack
- public Book(int id, string title, string subtitle, string author, int part, int pages)
- {
- this.id = id;
- this.title = title;
- this.subtitle = subtitle;
- this.author = author;
- this.part = part;
- this.pages = pages;
- }
- public string Title { get => title; set => title = value; }
- public string Subtitle { get => subtitle; set => subtitle = value; }
- public string Author { get => author; set => author = value; }
- public int Id { get => id; set => id = value; }
- public int Part { get => part; set => part = value; }
- public int Pages { get => pages; set => pages = value; }
- // Object > XML
- public void Book_Add(string path)
- {
- if (File.Exists(path))
- {
- XElement root = XElement.Load(path);
- root.Add(
- new XElement("book",
- new XElement("id", id),
- new XElement("title", title),
- new XElement("subtitle", subtitle),
- new XElement("author", author),
- new XElement("part", part),
- new XElement("pages", pages)
- )
- );
- root.Save(path);
- }
- else
- {
- XDocument catalogus = new XDocument(
- new XDeclaration("1.0", "UTF-8", null),
- new XElement("books",
- new XElement("book",
- new XElement("id", id),
- new XElement("title", title),
- new XElement("subtitle", subtitle),
- new XElement("author", author),
- new XElement("part", part),
- new XElement("pages", pages)
- )
- )
- );
- catalogus.Save(path);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement