コード例 #1
0
        public virtual string GenerateXmlString(IEnumerable <SiteMapItem> items)
        {
            var sitemapCount = (int)Math.Ceiling(items.Count() / (double)SiteMapHelper.MaximumSitemapIndexCount);

            SiteMapHelper.CheckSitemapCount(sitemapCount);

            if (items == null || !items.Any())
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "urlset",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "xsi", Xsi),
                             new XAttribute(Xsi + "schemaLocation",
                                            @"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SiteMapHelper.CheckDocumentSize(xml);

            return(xml);
        }
コード例 #2
0
        public virtual string GenerateXmlString(IEnumerable <SiteMapImageItem> items)
        {
            if (items == null || !items.Any())
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "urlset",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "image", Image),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SiteMapHelper.CheckDocumentSize(xml);
            return(xml);
        }
コード例 #3
0
        public virtual string GenerateXmlString(IEnumerable <SiteMapIndexItem> items)
        {
            if (items?.Any() != true)
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "sitemapindex",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "xsi", Xsi),
                             new XAttribute(Xsi + "schemaLocation",
                                            @"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SiteMapHelper.CheckDocumentSize(xml);
            return(xml);
        }