Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
 private void WriteText(string name, SyndicationWriter writer, Text text)
 {
     writer.WriteStartElement(name);
     writer.WriteAttributeString("type", text.Type);
     writer.WriteString(text.InnerText);
     writer.WriteEndElement();
 }
Exemplo n.º 7
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();
        }