示例#1
0
        public static List <Sitemap> GetSitemap()
        {
            List <Sitemap> smList = new List <Sitemap>();

            if (!File.Exists(dnsSitemapFileAddress))
            {
                DownloadSitemap();
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(dnsSitemapFileAddress);
                if (doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
                {
                    //READ PREPARING:

                    // Get the encoding declaration.
                    XmlDeclaration decl = (XmlDeclaration)doc.FirstChild;

                    // Set the encoding declaration.
                    decl.Encoding = "UTF-16";
                    string response = doc.InnerXml;

                    string filter = @"xmlns(:\w+)?=""([^""]+)""|xsi(:\w+)?=""([^""]+)""";
                    response = Regex.Replace(response, filter, "");

                    doc.LoadXml(response);

                    foreach (XmlNode parentNode in doc.SelectNodes("//url")) //sitemap
                    {
                        string parentNodeValue = parentNode.InnerText;

                        Sitemap sm = new Sitemap();

                        sm.ID  = Guid.NewGuid();
                        sm.Url = parentNode.SelectSingleNode("./loc").InnerText;
                        sm.LastModification = DateTime.Parse(parentNode.SelectSingleNode("./lastmod").InnerText);
                        sm.ChangeFreq       = parentNode.SelectSingleNode("./changefreq").InnerText;
                        string priority = parentNode.SelectSingleNode("./priority").InnerText.Replace(".", ",");
                        sm.Priority = float.Parse(priority);

                        smList.Add(sm);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //MessageBox.Show(ex.ToString());
            }

            return(smList);
        }
示例#2
0
        public static List<Sitemap> GetSitemap()
        {
            List<Sitemap> smList = new List<Sitemap>();

            if (!File.Exists(dnsSitemapFileAddress))
                DownloadSitemap();

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(dnsSitemapFileAddress);
                if (doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
                {
                    //READ PREPARING:

                    // Get the encoding declaration.
                    XmlDeclaration decl = (XmlDeclaration)doc.FirstChild;

                    // Set the encoding declaration.
                    decl.Encoding = "UTF-16";
                    string response = doc.InnerXml;

                    string filter = @"xmlns(:\w+)?=""([^""]+)""|xsi(:\w+)?=""([^""]+)""";
                    response = Regex.Replace(response, filter, "");

                    doc.LoadXml(response);

                    foreach (XmlNode parentNode in doc.SelectNodes("//url")) //sitemap
                    {
                        string parentNodeValue = parentNode.InnerText;

                        Sitemap sm = new Sitemap();

                        sm.ID = Guid.NewGuid();
                        sm.Url = parentNode.SelectSingleNode("./loc").InnerText;
                        sm.LastModification = DateTime.Parse(parentNode.SelectSingleNode("./lastmod").InnerText);
                        sm.ChangeFreq = parentNode.SelectSingleNode("./changefreq").InnerText;
                        string priority = parentNode.SelectSingleNode("./priority").InnerText.Replace(".",",");
                        sm.Priority = float.Parse(priority);

                        smList.Add(sm);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //MessageBox.Show(ex.ToString());
            }

            return smList;
        }