Beispiel #1
0
 private void AddSectionChildren(SyndicationWriter writer, SiteMapNodeCollection children)
 {
     foreach(SiteMapNode node in children)
     {
         this.AddSiteMap(writer, node);
         this.AddSectionChildren(writer, node.ChildNodes);
     }
 }
Beispiel #2
0
 private void AddSiteMap(SyndicationWriter writer, SiteMapNode node)
 {
     writer.WriteStartElement("sitemap");
     writer.WriteStartElement("loc");
     writer.WriteString(node.Url + "?sitemap");
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Beispiel #3
0
        private void WriteCategory(string name, SyndicationWriter writer, Category category)
        {
            writer.WriteStartElement(name);
            writer.WriteAttributeString("term", category.Term);

            if (category.Label != null)
                writer.WriteAttributeString("label", category.Label);

            if (category.SchemeUrl != null)
            {
                writer.WriteStartAttribute("scheme");
                writer.WriteValue(category.SchemeUrl);
                writer.WriteEndAttribute();
            }

            writer.WriteEndElement();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            using (SyndicationWriter writer = new SyndicationWriter(sb))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("feed");
                writer.WriteAttributeString("xmlns", "http://www.w3.org/2005/Atom");

                Feed feed = Common.ExecutingModule.Syndication;

                // write main part of feed
                WriteSource(writer, feed);

                // <entry>...
                foreach (Entry entry in feed.Items)
                    WriteEntry("entry", writer, entry);
            }
            return sb.ToString();
        }
Beispiel #6
0
        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            using (SyndicationWriter writer = new SyndicationWriter(sb))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("sitemapindex");
                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/siteindex.xsd");

                SiteMapNode node = SiteMap.CurrentNode;

                this.AddSiteMap(writer, node);
                this.AddSectionChildren(writer, node.ChildNodes);

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            // returns the generated sitemap index
            return sb.ToString();
        }
Beispiel #7
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();
        }
Beispiel #8
0
        private void WriteEntry(string name, SyndicationWriter writer, Entry entry)
        {
            writer.WriteStartElement("entry");

            // <title>
            WriteText("title", writer, entry.Title);

            // <updated>
            WriteDateTime("updated", writer, entry.Updated);

            // <published>
            if (entry.Published.HasValue)
                WriteDateTime("published", writer, entry.Published.Value);

            // <id>
            WriteId("id", writer, entry.Id);

            // <summary>
            if (entry.Summary != null)
                WriteText("summary", writer, entry.Summary);

            // <link>...
            foreach (Link link in entry.Links)
                WriteLink("link", writer, link);

            // <rights>
            if (entry.Rights != null)
                WriteText("rights", writer, entry.Rights);

            // <author>...
            foreach (Person person in entry.Authors)
                WritePerson("author", writer, person);

            // <contributor>...
            foreach (Person person in entry.Contributors)
                WritePerson("contributor", writer, person);

            // <category>...
            foreach (Category category in entry.Categories)
                WriteCategory("category", writer, category);

            // <content>
            if (entry.Content != null)
                WriteContent("content", writer, entry.Content);

            // <source>
            if (entry.Source != null)
            {
                writer.WriteStartElement("source");
                WriteSource(writer, entry.Source);
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Beispiel #9
0
 private void WriteDateTime(string name, SyndicationWriter writer, DateTime date)
 {
     writer.WriteStartElement(name);
     writer.WriteValue(date);
     writer.WriteEndElement();
 }
Beispiel #10
0
 private void WriteUri(string name, SyndicationWriter writer, Uri uri)
 {
     writer.WriteStartElement(name);
     writer.WriteValue(uri);
     writer.WriteEndElement();
 }
Beispiel #11
0
 private void WriteText(string name, SyndicationWriter writer, Text text)
 {
     writer.WriteStartElement(name);
     writer.WriteAttributeString("type", text.Type);
     writer.WriteString(text.InnerText);
     writer.WriteEndElement();
 }
Beispiel #12
0
        private void WriteSource(SyndicationWriter writer, Source source)
        {
            // <title>
            WriteText("title", writer, source.Title);

            // <subtitle>
            if (source.SubTitle != null)
                WriteText("subtitle", writer, source.SubTitle);

            // <updated>
            WriteDateTime("updated", writer, source.Updated);

            // <id>
            WriteId("id", writer, source.Id);

            // <link>...
            foreach (Link link in source.Links)
                WriteLink("link", writer, link);

            // <rights>
            if (source.Rights != null)
                WriteText("rights", writer, source.Rights);

            // <generator>
            if (source.Generator != null)
                WriteGenerator("generator", writer, source.Generator);

            // <author>...
            foreach (Person person in source.Authors)
                WritePerson("author", writer, person);

            // <contributor>...
            foreach (Person person in source.Contributors)
                WritePerson("contributor", writer, person);

            // <category>...
            foreach (Category category in source.Categories)
                WriteCategory("category", writer, category);

            // <logo>
            if (source.Logo != null)
                WriteUri("logo", writer, source.Logo);

            // <icon>
            if (source.Icon != null)
                WriteUri("icon", writer, source.Icon);
        }
Beispiel #13
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();
 }
Beispiel #14
0
        private void WriteLink(string name, SyndicationWriter writer, Link link)
        {
            writer.WriteStartElement(name);
            writer.WriteStartAttribute("href");
            writer.WriteValue(link.Href);
            writer.WriteEndAttribute();

            if (link.Relationship != LinkRelationship.NotDefined)
                writer.WriteAttributeString("rel", link.Relationship.ToString().ToLower());

            if (link.Type != null)
                writer.WriteAttributeString("type", link.Type);

            if (link.Language != null)
                writer.WriteAttributeString("hreflang", link.Language);

            if (link.Title != null)
                writer.WriteAttributeString("title", link.Title);

            if (link.Length.HasValue)
                writer.WriteAttributeString("length", link.Length.Value.ToString());

            writer.WriteEndElement();
        }
Beispiel #15
0
 private void WriteId(string name, SyndicationWriter writer, string id)
 {
     writer.WriteStartElement(name);
     writer.WriteValue(id);
     writer.WriteEndElement();
 }
Beispiel #16
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();
 }