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(); }
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(); }
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(); }
private void WriteDateTime(string name, SyndicationWriter writer, DateTime date) { writer.WriteStartElement(name); writer.WriteValue(date); writer.WriteEndElement(); }
private void WriteUri(string name, SyndicationWriter writer, Uri uri) { writer.WriteStartElement(name); writer.WriteValue(uri); writer.WriteEndElement(); }
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(); }
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(); }
private void WriteId(string name, SyndicationWriter writer, string id) { writer.WriteStartElement(name); writer.WriteValue(id); writer.WriteEndElement(); }
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(); }