User Tools

Site Tools


Sidebar

Nebol Software Projects:

.NET Class Libraries

Contact info:

johan@nebol.se

nebolbooks

This is an old revision of the document!


NebolBooks

books.xml is a file containing metadata about a short list of books. It's created by Microsoft and is used “in various samples throughout the Microsoft XML Core Services (MSXML) SDK”

You can find the original file here: External Link

NebolBooks is a small framework for reading and parsing this file into a collection of inter-linked objects. The metadata for each book is: id, author, title, genre, price, publish_date and description.

NebolBooks will create a list of books, a list of authors, and a list of genres and then link them together.


Usage

Add nuget packages

If you haven't done so already, add the nuget.nebol.se repository to Visual Studio by running this in Package Manager:

nuget sources add -name nuget.nebol.se -source https://nuget.nebol.se/api/odata

Then add the package:

Install-Package NebolBooks

The next step is to load the book metadata (which is embedded into NebolBooks) into a Library object by calling this static method:

var library = Library.ParseBooks();

There's another option, reading the books from a properly formatted xml file that you supply:

var library = Library.ParseBooks(@"D:\my_own_books.xml");

Now we have access to the data and we can use it as we please:

// iterate through the books and print out some info
int genre_id = 0;
foreach (var book in library.Books.OrderBy(item => item.GenreID))
{
	if (book.GenreID != genre_id)
	{
		genre_id = book.GenreID;
		string genre_name = library.Genres.First(item => item.ID == genre_id).Name;
		Console.WriteLine("\nGenre: " + genre_name);
	}
 
	string author_name = library.Authors.First(item => item.ID == book.AuthorID).Name;
 
	Console.WriteLine("Book ID " + book.ID + ": \"" + book.Title + "\" by " + author_name + " ($" + book.Price + ")");
}

The output should look like this:

Genre: Computer
Book ID bk101: "XML Developer's Guide" by Gambardella, Matthew ($44,95)
Book ID bk110: "Microsoft .NET: The Programming Bible" by O'Brien, Tim ($36,95)
Book ID bk111: "MSXML3: A Comprehensive Guide" by O'Brien, Tim ($36,95)
Book ID bk112: "Visual Studio 7: A Comprehensive Guide" by Galos, Mike ($49,95)

Genre: Fantasy
Book ID bk102: "Midnight Rain" by Ralls, Kim ($5,95)
Book ID bk103: "Maeve Ascendant" by Corets, Eva ($5,95)
Book ID bk104: "Oberon's Legacy" by Corets, Eva ($5,95)
Book ID bk105: "The Sundered Grail" by Corets, Eva ($5,95)

Genre: Romance
Book ID bk106: "Lover Birds" by Randall, Cynthia ($4,95)
Book ID bk107: "Splish Splash" by Thurman, Paula ($4,95)

Genre: Horror
Book ID bk108: "Creepy Crawlies" by Knorr, Stefan ($4,95)

Genre: Science Fiction
Book ID bk109: "Paradox Lost" by Kress, Peter ($6,95)
nebolbooks.1582409845.txt.gz · Last modified: 2020/02/22 23:17 by 127.0.0.1