Beispiel #1
0
        private static List <Book> BooksFromNode(HtmlNodeCollection nodeCollection)
        {
            /*
             * <dc_relation>
             *  <MEK>
             *      <MEK_name>Gárdonyi Géza: Bojgás az világba</MEK_name>
             *      <MEK_URL>http://mek.oszk.hu/05700/05712/</MEK_URL>
             *  </MEK>
             * </dc_relation>
             */
            var books = new List <Book>();

            foreach (var node in nodeCollection)
            {
                try
                {
                    var title   = node.ChildNodes["mek"]?.ChildNodes["mek_name"]?.InnerText;
                    var url     = node.ChildNodes["mek"]?.ChildNodes["mek_url"]?.InnerText;
                    var catalog = CatalogResolver.Resolve(url);
                    books.Add(new Book()
                    {
                        FullTitle = MekConvert.ClearText(title),
                        Id        = catalog?.Id,
                        UrlId     = catalog?.UrlId
                    });
                }
                catch
                {
                    //TODO: log
                }
            }
            return(books);
        }
Beispiel #2
0
        public static Book CreateBookFromIndex(string content)
        {
            var book = new Book();
            var html = new HtmlDocument();

            html.Load(new StringReader(content));
            var doc = html.DocumentNode;

            var url     = StringFromNode(doc.SelectNodes("//mek2/dc_identifier/url"));
            var catalog = CatalogResolver.Resolve(url);

            book.Id              = catalog?.Id;
            book.UrlId           = catalog?.UrlId;
            book.Metadata.MekUrl = url;
            book.MekId           = StringFromNode(doc.SelectNodes("//mek2/dc_identifier/mekid"));
            book.Urn             = StringFromNode(doc.SelectNodes("//mek2/dc_identifier/urn"));

            book.Title = MekConvert.ClearText(StringFromNode(doc.SelectNodes("//mek2/dc_title/main")));

            Uri source = null;

            Uri.TryCreate(StringFromNode(doc.SelectNodes("//mek2/dc_source/act_url")), UriKind.RelativeOrAbsolute, out source);
            book.Source = source;

            book.Type = StringListFromNode(doc.SelectNodes("//mek2/dc_type"));

            book.Topics = new List <string>();
            book.Topics.Add(StringFromNode(doc.SelectNodes("//mek2/dc_subject/topicgroup/broadtopic")));
            book.Topics.Add(StringFromNode(doc.SelectNodes("//mek2/dc_subject/topicgroup/topic")));
            book.Topics.Add(StringFromNode(doc.SelectNodes("//mek2/dc_subject/topicgroup/subtopic")));

            book.KeyWords = StringListFromNode(doc.SelectNodes("//mek2/dc_subject/keyword"));

            book.Period   = StringFromNode(doc.SelectNodes("//mek2/dc_subject/period"));
            book.Language = StringFromNode(doc.SelectNodes("//mek2/dc_language/lang"));

            book.Creators     = ContributorsFromNode(doc.SelectNodes("//mek2/dc_creator"));
            book.Author       = book.Creators?.First()?.ToString();
            book.Contributors = ContributorsFromNode(doc.SelectNodes("//mek2/dc_contributor"));

            var publisher = doc.SelectNodes("//mek2/dc_publisher")?.First();

            if (publisher != null)
            {
                book.Publisher    = MekConvert.ClearText(publisher.ChildNodes["pub_name"]?.InnerText);
                book.PublishPlace = MekConvert.ClearText(publisher.ChildNodes["place"]?.InnerText);
                book.PublishYear  = MekConvert.ClearText(publisher.ChildNodes["publishYear"]?.InnerText);
            }

            book.Related = BooksFromNode(doc.SelectNodes("//mek2/dc_relation"));

            return(book);
        }