Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }