Example #1
0
 private void AddSiteMap(SyndicationWriter writer, SiteMapNode node)
 {
     writer.WriteStartElement("sitemap");
     writer.WriteStartElement("loc");
     writer.WriteString(node.Url + "?sitemap");
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Example #2
0
        private void WriteContent(string name, SyndicationWriter writer, Content content)
        {
            writer.WriteStartElement(name);
            writer.WriteAttributeString("type", content.Type);

            // checks which to write to the output of the content
            // you can either write a source URL or text, but not both
            if (content.SourceUrl != null)
            {
                writer.WriteStartAttribute("src");
                writer.WriteValue(content.SourceUrl);
                writer.WriteEndAttribute();
            }
            else
            {
                writer.WriteString(content.InnerText);
            }

            writer.WriteEndElement();
        }
Example #3
0
        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            using (SyndicationWriter writer = new SyndicationWriter(sb))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset");
                writer.WriteAttributeString("xmlns", "http://www.google.com/schemas/sitemap/0.84");
                writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                writer.WriteAttributeString("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.google.com/schemas/sitemap/0.84/sitemap.xsd");

                Feed feed = Common.ExecutingModule.Syndication;

                writer.WriteStartElement("url");

                writer.WriteStartElement("loc");
                writer.WriteValue(feed.Id);
                writer.WriteEndElement();

                writer.WriteStartElement("lastmod");
                writer.WriteValue(feed.Updated);
                writer.WriteEndElement();

                if (feed.ChangeFrequency != ChangeFrequency.NotDefined)
                {
                    writer.WriteStartElement("changefreq");
                    writer.WriteString(feed.ChangeFrequency.ToString().ToLower());
                    writer.WriteEndElement();
                }

                if (feed.Priority.HasValue)
                {
                    writer.WriteStartElement("priority");
                    writer.WriteString(feed.Priority.Value.ToString("f1"));
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();

                foreach (Entry entry in feed.Items)
                {
                    writer.WriteStartElement("url");

                    writer.WriteStartElement("loc");
                    writer.WriteValue(entry.Id);
                    writer.WriteEndElement();

                    writer.WriteStartElement("lastmod");
                    writer.WriteValue(entry.Updated);
                    writer.WriteEndElement();

                    if (entry.ChangeFrequency != ChangeFrequency.NotDefined)
                    {
                        writer.WriteStartElement("changefreq");
                        writer.WriteString(entry.ChangeFrequency.ToString().ToLower());
                        writer.WriteEndElement();
                    }

                    if (entry.Priority.HasValue)
                    {
                        writer.WriteStartElement("priority");
                        writer.WriteString(entry.Priority.Value.ToString("f1"));
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return sb.ToString();
        }
Example #4
0
 private void WriteText(string name, SyndicationWriter writer, Text text)
 {
     writer.WriteStartElement(name);
     writer.WriteAttributeString("type", text.Type);
     writer.WriteString(text.InnerText);
     writer.WriteEndElement();
 }
Example #5
0
 private void WritePerson(string name, SyndicationWriter writer, Person person)
 {
     writer.WriteStartElement(name);
     writer.WriteStartElement("name");
     writer.WriteString(person.Name);
     writer.WriteEndElement();
     writer.WriteStartElement("uri");
     writer.WriteValue(person.Link);
     writer.WriteEndElement();
     writer.WriteStartElement("email");
     writer.WriteString(person.Email);
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Example #6
0
 private void WriteGenerator(string name, SyndicationWriter writer, Generator generator)
 {
     writer.WriteStartElement(name);
     writer.WriteStartAttribute("uri");
     writer.WriteValue(generator.Url);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute("version");
     writer.WriteString(generator.Version.ToString());
     writer.WriteEndAttribute();
     writer.WriteString(generator.InnerText);
     writer.WriteEndElement();
 }