c#生成站点地图(SiteMapPath)文件示例程序
时间:2022-08-03 02:26:55
//创建站点地图
private void CreateSiteMap(DataSet ds)
{
XmlDeclaration declareation;
declareation = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(declareation);
XmlElement xeRoot = xmlDoc.CreateElement("siteMap");
xmlDoc.AppendChild(xeRoot);
XmlElement xroot = xmlDoc.CreateElement("siteMapNode");
xroot.SetAttribute("title", "");
xroot.SetAttribute("url", "#");
xeRoot.AppendChild(xroot);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
DataRowView row = ds.Tables[0].DefaultView[i];
string MainMenu = row["MainMenu"].ToString();
string NavigateUrl = row["NavigateUrl"].ToString();
if (MainMenu != str)
{
XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");
siteMapNode.SetAttribute("title", MainMenu);
siteMapNode.SetAttribute("description", "");
siteMapNode.SetAttribute("url", NavigateUrl);
xroot.AppendChild(siteMapNode);
str = AddChildNode(MainMenu);
}
}
xmlDoc.Save(Server.MapPath("\\Web.sitemap"));
}
//添加子节点
private string AddChildNode(String text)
{
string sql = "select * from Menu Where MainMenu ='" + text + "'";
DataSql data = new DataSql();
data.DataCon();
DataSet ds = data.GetDataset(sql);
XmlNode root = xmlDoc.SelectSingleNode("/siteMap/siteMapNode/siteMapNode[@title='" + text + "']");
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
DataRowView row = ds.Tables[0].DefaultView[i];
string ChildMenu = row["ChildMenu"].ToString();
if (ChildMenu != "")
{
string NavigateUrl = row["NavigateUrl"].ToString();
XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");
siteMapNode.SetAttribute("title", ChildMenu);
siteMapNode.SetAttribute("description", "");
siteMapNode.SetAttribute("url", NavigateUrl);
root.AppendChild(siteMapNode);
}
}
return text;
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java剑指offer之删除链表的节点
Java多线程 Guarded Suspension设计模式
jvm虚拟机类加载机制详解
![](https://img.aspxhome.com/file/2023/7/76497_0s.jpg)
详解JAVAEE——SSH三大框架整合(spring+struts2+hibernate)
![](https://img.aspxhome.com/file/2023/8/68758_0s.png)
C#使用三层架构开发Winform的详细案例
![](https://img.aspxhome.com/file/2023/9/67569_0s.jpg)
SpringBoot+Spring Security+JWT实现RESTful Api权限控制的方法
![](https://img.aspxhome.com/file/2023/4/65604_0s.png)
UnityUI中绘制线状统计图
![](https://img.aspxhome.com/file/2023/6/82146_0s.jpg)
C# 特殊的string类型详解
java多线程实现下载图片并压缩
详解IDEA多module项目maven依赖的一些说明
![](https://img.aspxhome.com/file/2023/4/67974_0s.png)
Java实例讲解Comparator的使用
Spring JPA联表查询之OneToOne源码详解
![](https://img.aspxhome.com/file/2023/3/67603_0s.jpg)
SpringMVC编程使用Controller接口实现控制器实例代码
Java多态的全面系统解析
![](https://img.aspxhome.com/file/2023/9/77119_0s.png)
spring+srpingmvc+hibernate实现动态ztree生成树状图效果
Spring Data JPA 之 JpaRepository的使用
![](https://img.aspxhome.com/file/2023/4/60114_0s.jpg)
javaweb Servlet开发总结(二)
![](https://img.aspxhome.com/file/2023/7/58567_0s.png)
Spring如何基于注解配置使用ehcache
Android带进度的圆形进度条
![](https://img.aspxhome.com/file/2023/8/86748_0s.jpg)