Example #1
0
        /// <summary>
        /// 保存XML
        /// </summary>
        /// <param name="filename"></param>
        public void SaveBook(string filename)
        {
            FileInfo fileinfo = new FileInfo(filename);
            if (fileinfo.Directory.Exists == false)
                Directory.CreateDirectory(fileinfo.DirectoryName);

            string strxml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                                            <root>
                                            <book rule="""" baseurl="""">
                                              <title></title>
                                              <auther></auther>
                                              <cover></cover>
                                              <introduction></introduction>
                                              <catalogs>
                                              </catalogs>
                                              <content>
                                              </content>
                                            </book>
                                            </root>";
            XmlHandle xmlhandle = new XmlHandle(filename, strxml);
            xmlhandle.SetValue("book", "rule", rule);
            xmlhandle.SetValue("book", "baseurl", baseurl);
            xmlhandle.SetValue("book/title", title);
            xmlhandle.SetValue("book/auther", auther);
            xmlhandle.SetValue("book/cover", cover);
            xmlhandle.SetValue("book/introduction", introduction);
            for (int i = 0; i < catalogs.Count; i++)
            {
                XmlElement node = xmlhandle.AddNode("book/catalogs", "catalog");
                node.SetAttribute("url", catalogs[i].url);
                node.InnerText = catalogs[i].text;
                if (catalogs[i].page != null)
                {
                    node.SetAttribute("index", catalogs[i].page.index.ToString());
                    XmlElement node1 = xmlhandle.AddNode("book/content", "page");
                    node1.SetAttribute("index", catalogs[i].page.index.ToString());
                    node1.InnerText = catalogs[i].page.text;
                }
            }

            xmlhandle.SaveConfig();
        }
Example #2
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);
            }
        }
Example #3
0
        public static void SaveXml(SearchRule rule)
        {
            XmlHandle xmlhandle = new XmlHandle(bookrulexml);
            if (xmlhandle.GetCount("SearchSite[Name=" + rule.name + "]") > 0)//更新
            {
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]", "SearchUrl", rule.searchurl);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]", "charset", rule.charset);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]", "list", rule.list_rule);

                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]/title", rule.title_rule);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]/auther", rule.auther_rule);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]/cover", rule.cover_rule);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]/introduction", rule.introduction_rule);
                xmlhandle.SetValue("SearchSite[Name=" + rule.name + "]/bookurl", rule.bookurl_rule);
            }
            else//新增
            {
                XmlElement node = xmlhandle.AddNode("SearchSite");
                node.SetAttribute("Name", rule.name);
                node.SetAttribute("SearchUrl", rule.searchurl);
                node.SetAttribute("charset", rule.charset);
                node.SetAttribute("list", rule.list_rule);

                XmlElement node1 = xmlhandle.AddNode(node, "title");
                node1.InnerText = rule.title_rule;

                XmlElement node2 = xmlhandle.AddNode(node, "auther");
                node2.InnerText = rule.auther_rule;

                XmlElement node3 = xmlhandle.AddNode(node, "cover");
                node3.InnerText = rule.cover_rule;

                XmlElement node4 = xmlhandle.AddNode(node, "introduction");
                node4.InnerText = rule.introduction_rule;

                XmlElement node5 = xmlhandle.AddNode(node, "bookurl");
                node5.InnerText = rule.bookurl_rule;
            }
            xmlhandle.SaveConfig();
        }
Example #4
0
        public static void LoadXml()
        {
            XmlHandle xmlhandle = new XmlHandle(bookrulexml);
            int num = xmlhandle.GetCount("BookSite");
            if (num > 0) _rulelist = new List<BookRule>();
            for (int i = 1; i <= num; i++)
            {
                BookRule rule = new BookRule();
                rule.name = xmlhandle.GetValue("BookSite[" + i + "]", "Name");
                rule.url = xmlhandle.GetValue("BookSite[" + i + "]", "Url");
                rule.charset = xmlhandle.GetValue("BookSite[" + i + "]", "charset");
                rule.title_rule = xmlhandle.GetValue("BookSite[" + i + "]/title");
                rule.auther_rule = xmlhandle.GetValue("BookSite[" + i + "]/auther");
                rule.cover_rule = xmlhandle.GetValue("BookSite[" + i + "]/cover");
                rule.introduction_rule = xmlhandle.GetValue("BookSite[" + i + "]/introduction");
                rule.catalog_rule = xmlhandle.GetValue("BookSite[" + i + "]/catalog");
                rule.content_rule = xmlhandle.GetValue("BookSite[" + i + "]/content");
                _rulelist.Add(rule);
            }

            num = xmlhandle.GetCount("SearchSite");
            if (num > 0) _searchrulelist = new List<SearchRule>();
            for (int i = 1; i <= num; i++)
            {
                SearchRule rule = new SearchRule();
                rule.name = xmlhandle.GetValue("SearchSite[" + i + "]", "Name");
                rule.searchurl = xmlhandle.GetValue("SearchSite[" + i + "]", "SearchUrl");
                rule.charset = xmlhandle.GetValue("SearchSite[" + i + "]", "charset");

                rule.list_rule = xmlhandle.GetValue("SearchSite[" + i + "]", "list");

                rule.conditions =new List<RuleConditions>();
                rule.title_rule = xmlhandle.GetValue("SearchSite[" + i + "]/title");
                XmlAttributeCollection attcoll = xmlhandle.GetAttributes("SearchSite[" + i + "]/title");
                foreach (XmlAttribute v in attcoll)
                {
                    RuleConditions cond = new RuleConditions();
                    cond.name = "title";
                    cond.conditionName = v.Name;
                    cond.conditionValue = v.Value;
                    rule.conditions.Add(cond);
                }
                rule.auther_rule = xmlhandle.GetValue("SearchSite[" + i + "]/auther");
                attcoll = xmlhandle.GetAttributes("SearchSite[" + i + "]/auther");
                foreach (XmlAttribute v in attcoll)
                {
                    RuleConditions cond = new RuleConditions();
                    cond.name = "auther";
                    cond.conditionName = v.Name;
                    cond.conditionValue = v.Value;
                    rule.conditions.Add(cond);
                }
                rule.cover_rule = xmlhandle.GetValue("SearchSite[" + i + "]/cover");
                attcoll = xmlhandle.GetAttributes("SearchSite[" + i + "]/cover");
                foreach (XmlAttribute v in attcoll)
                {
                    RuleConditions cond = new RuleConditions();
                    cond.name = "cover";
                    cond.conditionName = v.Name;
                    cond.conditionValue = v.Value;
                    rule.conditions.Add(cond);
                }

                rule.introduction_rule = xmlhandle.GetValue("SearchSite[" + i + "]/introduction");
                attcoll = xmlhandle.GetAttributes("SearchSite[" + i + "]/introduction");
                foreach (XmlAttribute v in attcoll)
                {
                    RuleConditions cond = new RuleConditions();
                    cond.name = "introduction";
                    cond.conditionName = v.Name;
                    cond.conditionValue = v.Value;
                    rule.conditions.Add(cond);
                }

                rule.bookurl_rule = xmlhandle.GetValue("SearchSite[" + i + "]/bookurl");
                attcoll = xmlhandle.GetAttributes("SearchSite[" + i + "]/bookurl");
                foreach (XmlAttribute v in attcoll)
                {
                    RuleConditions cond = new RuleConditions();
                    cond.name = "bookurl";
                    cond.conditionName = v.Name;
                    cond.conditionValue = v.Value;
                    rule.conditions.Add(cond);
                }

                _searchrulelist.Add(rule);
            }
        }
Example #5
0
        public static void SaveXml(BookRule rule)
        {
            XmlHandle xmlhandle = new XmlHandle(bookrulexml);
            if (xmlhandle.GetCount("BookSite[Name=" + rule.name + "]") > 0)//更新
            {
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]", "Url", rule.url);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]", "charset", rule.charset);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/title", rule.title_rule);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/auther", rule.auther_rule);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/cover", rule.cover_rule);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/introduction", rule.introduction_rule);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/catalog", rule.catalog_rule);
                xmlhandle.SetValue("BookSite[Name=" + rule.name + "]/content", rule.content_rule);
            }
            else//新增
            {
                XmlElement node = xmlhandle.AddNode("BookSite");
                node.SetAttribute("Name", rule.name);
                node.SetAttribute("Url", rule.url);
                node.SetAttribute("charset", rule.charset);

                XmlElement node1 = xmlhandle.AddNode(node, "title");
                node1.InnerText = rule.title_rule;

                XmlElement node2 = xmlhandle.AddNode(node, "auther");
                node2.InnerText = rule.auther_rule;

                XmlElement node3 = xmlhandle.AddNode(node, "cover");
                node3.InnerText = rule.cover_rule;

                XmlElement node4 = xmlhandle.AddNode(node, "introduction");
                node4.InnerText = rule.introduction_rule;

                XmlElement node5 = xmlhandle.AddNode(node, "catalog");
                node5.InnerText = rule.catalog_rule;

                XmlElement node6 = xmlhandle.AddNode(node, "content");
                node6.InnerText = rule.content_rule;
            }
            xmlhandle.SaveConfig();
        }