Beispiel #1
0
        /// <summary>
        /// 导入XML
        /// </summary>
        /// <param name="filename"></param>
        public void LoadBook(string filename)
        {
            XmlHandle xmlhandle = new XmlHandle(filename);
            rule = xmlhandle.GetValue("book", "rule");
            baseurl = xmlhandle.GetValue("book", "baseurl");
            title = xmlhandle.GetValue("book/title");
            auther = xmlhandle.GetValue("book/auther");
            cover = xmlhandle.GetValue("book/cover");
            introduction = xmlhandle.GetValue("book/introduction");
            int count = xmlhandle.GetCount("book/catalogs/catalog");
            catalogs = new List<BookCatalog>();
            for (int i = 1; i <= count; i++)
            {
                BookCatalog bc = new BookCatalog();
                bc.index = Convert.ToInt32(xmlhandle.GetValue("book/catalogs/catalog[" + i + "]", "index"));
                bc.url = xmlhandle.GetValue("book/catalogs/catalog[" + i + "]", "url");
                bc.text = xmlhandle.GetValue("book/catalogs/catalog[" + i + "]");
                bc.page = new BookPage();
                bc.page.index = bc.index;
                bc.page.text = xmlhandle.GetValue("book/content/page[" + i + "]");

                catalogs.Add(bc);
            }
        }
Beispiel #2
0
        private static void ParseCatalog(Uri uri,string html, Book book, BookRule rule)
        {
            string buffer;
            NSoup.Nodes.Document doc = html == null ? NSoupHelper.GetNSoupDoc(uri.ToString(), rule.charset, out buffer) : NSoupHelper.GetNSoupDoc(html);
            if (doc == null) return;

            if (rule.title_rule != "")
            {
                book.title = doc.Select(rule.title_rule).Text;
            }
            if (rule.auther_rule != "")
            {
                book.auther = doc.Select(rule.auther_rule).Text;
            }
            if (rule.cover_rule != "")
            {
                book.cover = doc.Select(rule.cover_rule).Text;
            }
            if (rule.introduction_rule != "")
            {
                book.introduction = doc.Select(rule.introduction_rule).Text;
            }
            if (rule.catalog_rule != "")
            {
                var catalog = doc.Select(rule.catalog_rule);
                if (catalog.Count > 0)
                {
                    book.catalogs = new List<BookCatalog>();
                    for (int i = 0; i < catalog.Count; i++)
                    {
                        BookCatalog bc = new BookCatalog();
                        bc.index = i;
                        bc.url = catalog[i].Attr("href");
                        bc.text = catalog[i].Text();
                        bc.baseurl = uri.ToString();
                        bc.bookrule = rule;

                        book.catalogs.Add(bc);
                    }
                }
            }
        }