Beispiel #1
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();
        }
Beispiel #2
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();
        }
Beispiel #3
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();
        }