/// <summary> /// Creates a sitemap.xml fragment and appends it to the sitemap.xml document in progress. /// </summary> /// <param name="doc">The sitemap.xml document in progress.</param> /// <param name="node">The node to process.</param> public static void AppendUrlElement(XmlDocument doc, ISitemapNode node) { var url = doc.CreateElement("url"); var locElement = doc.CreateElement("loc"); locElement.InnerText = node.Location; var lastModElement = doc.CreateElement("lastmod"); lastModElement.InnerText = node.LastModified.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); var changeFreqElement = doc.CreateElement("changefreq"); changeFreqElement.InnerText = node.ChangeFrequency.ToString().ToLower(CultureInfo.InvariantCulture); var priorityElement = doc.CreateElement("priority"); priorityElement.InnerText = node.Priority.ToString(CultureInfo.InvariantCulture); url.AppendChild(locElement); url.AppendChild(lastModElement); url.AppendChild(changeFreqElement); url.AppendChild(priorityElement); // ReSharper disable PossibleNullReferenceException doc.DocumentElement.AppendChild(url); // ReSharper restore PossibleNullReferenceException }
/// <summary> /// Creates a sitemap.xml fragment and appends it to the sitemap.xml document in progress. /// </summary> /// <param name="node">The node to process.</param> protected virtual void AppendUrlElement(ISitemapNode node) { var url = Document.CreateElement("url"); var locElement = Document.CreateElement("loc"); locElement.InnerText = node.Location; url.AppendChild(locElement); if (SitemapXmlConfiguration.Current.IncludeLastMod) { var lastModElement = Document.CreateElement("lastmod"); lastModElement.InnerText = node.LastModified.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); url.AppendChild(lastModElement); } if (SitemapXmlConfiguration.Current.IncludeChangeFrequency) { var changeFreqElement = Document.CreateElement("changefreq"); changeFreqElement.InnerText = node.ChangeFrequency.ToString().ToLower(CultureInfo.InvariantCulture); url.AppendChild(changeFreqElement); } if (SitemapXmlConfiguration.Current.IncludePriority) { var priorityElement = Document.CreateElement("priority"); priorityElement.InnerText = node.Priority.ToString(CultureInfo.InvariantCulture); url.AppendChild(priorityElement); } // ReSharper disable PossibleNullReferenceException Document.DocumentElement.AppendChild(url); // ReSharper restore PossibleNullReferenceException }
public static void Validate(ISitemapNode node) { if (node == null) throw new ArgumentNullException("node"); if (string.IsNullOrWhiteSpace(node.Location)) throw new ArgumentNullException("node.Location", "Location is required."); if (!node.Location.StartsWith("http://") && !node.Location.StartsWith("https://")) throw new ArgumentException("node.Location", "Location must start with http:// or https://"); if (node.Location.Length > 2048) throw new ArgumentException("node.Location", "Location cannot be longer than 2048 characters."); if (node.Priority.HasValue && (node.Priority < 0 || node.Priority > 1)) throw new ArgumentException("node.Priority", "Priority must be between 0.0 and 1.0."); }
private static SitemapNode GetSitemapNode(Guid pageId, ISitemapNode root) { foreach (var childNode in root.ChildNodes) { if (childNode.Page.ContentId == pageId) { return(childNode); } var found = GetSitemapNode(pageId, childNode); if (found != null) { return(found); } } return(null); }
private static void AttachChildNodes(ISitemapNode sitemapNode, ISiteStructureNode node, string path, Dictionary <Guid, CmsPage> allPages) { foreach (var childStructureNode in node.ChildNodes) { var childSitemapNode = new SitemapNode(); if (!allPages.ContainsKey(childStructureNode.PageId)) { continue; } childSitemapNode.Page = allPages[childStructureNode.PageId]; childSitemapNode.VirtualPath = new Uri(path + "/" + childSitemapNode.Page.Slug, UriKind.Relative); sitemapNode.ChildNodes.Add(childSitemapNode); AttachChildNodes(childSitemapNode, childStructureNode, childSitemapNode.VirtualPath.ToString(), allPages); } }
/// <summary> /// Allows you to set changes all at once by using a SiteMapConfigurator node /// </summary> /// <param name="changes">the changes to be mapped</param> /// <returns></returns> public ISitemapConfigurator Set(ISitemapNode changes) { WithChangeFrequency(changes.ChangeFrequency) .WithLastModified(changes.LastModified) .WithLastModified(changes.LastModified) .WithPriority(changes.Priority); return Set(); }