Exemplo n.º 1
0
        public void Add(SitemapUrl _url)
        {
            _sitemapxml.WriteStartElement("url");
            _sitemapxml.WriteElementString("loc", _url.Loc);

            if (_url.LastModifiedString != "")
            {
                _sitemapxml.WriteElementString("lastmod", _url.LastModifiedString);
            }

            if (_url.ChangeFreq != ChangeFrequency.Never)
            {
                _sitemapxml.WriteElementString("changefreq", _url.ChangeFreq.ToString().ToLower());
            }

            if (_url.Priority != "")
            {
                _sitemapxml.WriteElementString("priority", _url.Priority);
            }

            if (_url.MapImages != null)
            {
                foreach (var img in _url.MapImages.Where(x => x.Loc.IsNullOrEmpty() == false))
                {
                    /*
                     * <image:image>
                     * <image:loc>http://example.com/image.jpg</image:loc>
                     * </image:image>
                     *
                     * <image:loc> 是 图片的网址。
                     * <image:caption>  可选 图片的说明。
                     * <image:geo_location> 可选 图片的地理位置。例如,<image:geo_location>Limerick, Ireland</image:geo_location>。
                     * <image:title> 可选 图片的标题。
                     * <image:license> 可选 指向图片许可的网址。
                     *
                     */
                    //image:image
                    _sitemapxml.WriteStartElement("image:image");

                    _sitemapxml.WriteStartElement("image:loc");
                    _sitemapxml.WriteString(img.Loc);
                    _sitemapxml.WriteEndElement();

                    if (img.Caption.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:caption");
                        _sitemapxml.WriteString(img.Caption);
                        _sitemapxml.WriteEndElement();
                    }

                    if (img.geo_location.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:geo_location");
                        _sitemapxml.WriteString(img.geo_location);
                        _sitemapxml.WriteEndElement();
                    }
                    if (img.Title.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:title");
                        _sitemapxml.WriteString(img.Title);
                        _sitemapxml.WriteEndElement();
                    }
                    if (img.License.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:license");
                        _sitemapxml.WriteString(img.License);
                        _sitemapxml.WriteEndElement();
                    }

                    _sitemapxml.WriteEndElement();
                }
            }

            _sitemapxml.WriteEndElement();
            _sitemapxml.Flush();
        }
Exemplo n.º 2
0
        public void Add(SitemapUrl _url)
        {
            _sitemapxml.WriteStartElement("url");
            _sitemapxml.WriteElementString("loc", _url.Loc);

            if (_url.LastModifiedString != "")
            {
                _sitemapxml.WriteElementString("lastmod", _url.LastModifiedString);
            }

            if (_url.ChangeFreq != ChangeFrequency.Never)
            {
                _sitemapxml.WriteElementString("changefreq", _url.ChangeFreq.ToString().ToLower());
            }

            if (_url.Priority != "")
            {
                _sitemapxml.WriteElementString("priority", _url.Priority);
            }

            if (_url.MapImages != null)
            {
                foreach (var img in _url.MapImages.Where(x => x.Loc.IsNullOrEmpty() == false))
                {
                    /*
            <image:image>
            <image:loc>http://example.com/image.jpg</image:loc>
            </image:image>

             <image:loc> 是 图片的网址。
            <image:caption>  可选 图片的说明。
            <image:geo_location> 可选 图片的地理位置。例如,<image:geo_location>Limerick, Ireland</image:geo_location>。
            <image:title> 可选 图片的标题。
            <image:license> 可选 指向图片许可的网址。

                     */
                    //image:image
                    _sitemapxml.WriteStartElement("image:image");

                    _sitemapxml.WriteStartElement("image:loc");
                    _sitemapxml.WriteString(img.Loc);
                    _sitemapxml.WriteEndElement();

                    if (img.Caption.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:caption");
                        _sitemapxml.WriteString(img.Caption);
                        _sitemapxml.WriteEndElement();
                    }

                    if (img.geo_location.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:geo_location");
                        _sitemapxml.WriteString(img.geo_location);
                        _sitemapxml.WriteEndElement();
                    }
                    if (img.Title.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:title");
                        _sitemapxml.WriteString(img.Title);
                        _sitemapxml.WriteEndElement();
                    }
                    if (img.License.IsNullOrEmpty() == false)
                    {
                        _sitemapxml.WriteStartElement("image:license");
                        _sitemapxml.WriteString(img.License);
                        _sitemapxml.WriteEndElement();
                    }

                    _sitemapxml.WriteEndElement();
                }
            }

            _sitemapxml.WriteEndElement();
            _sitemapxml.Flush();
        }