c#生成站点地图(SiteMapPath)文件示例程序
时间:03月15日

复制代码 代码如下:

//创建站点地图
??????? 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;
??????? }

最新动态
大家感兴趣的内容
关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿
严禁网站镜像,否则追究法律责任 CopyRight © 2015-2018 诺心网络 All Rights Reserved.
地址:杭州拱墅区祥园路38号浙报理想祥园创意园东区A319
电话:18958065710 微信:Evtailun 邮箱:476565345@qq.com
浙ICP备15017827号-1