Navigation.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web;
  4. using System.Xml;
  5. using System.Xml.Linq;
  6. namespace CD67.ModeleMVC.MVC.Internal
  7. {
  8. public static class Navigation
  9. {
  10. public static string SMap(SiteMapNode node)
  11. {
  12. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  13. List<SiteMapNode> nodes = new List<SiteMapNode>();
  14. nodes.Add(node);
  15. if (SiteMap.CurrentNode.ParentNode != null)
  16. {
  17. SMap(SiteMap.CurrentNode.ParentNode);
  18. }
  19. nodes.Reverse();
  20. sb.Append("<ul>");
  21. foreach (SiteMapNode nodeelem in nodes)
  22. {
  23. sb.Append(string.Concat("<li><a href=\"", nodeelem.Url, "\">", nodeelem.Title, "</a></li>"));
  24. }
  25. sb.Append("</ul>");
  26. return sb.ToString();
  27. }
  28. public static string Xmap(string title)
  29. {
  30. string toto = "";
  31. XDocument xmap = XDocument.Load("~/web.sitemap");
  32. var current = xmap.Ancestors("SiteMapNode")
  33. .Where(x => (string)x.Attribute("title") == title);
  34. current.Reverse();
  35. foreach(var currence in current)
  36. {
  37. toto += currence.Attribute("title").Value;
  38. }
  39. return toto;
  40. }
  41. public static string XmlMap(string title)
  42. {
  43. string toto = "";
  44. XmlDocument xml = new XmlDocument();
  45. xml.Load(HttpContext.Current.Server.MapPath("/web.sitemap"));
  46. XmlNodeList nodes = xml.DocumentElement.SelectNodes("//*[@title='" + title + "']/ancestor-or-self::SiteMapNode");
  47. foreach(XmlNode node in nodes)
  48. {
  49. toto += node.Attributes["title"].Value;
  50. }
  51. return toto;
  52. }
  53. }
  54. }