c#生成站點地圖(SiteMapPath)文件示例程序
//創(chuàng)建站點地圖
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"));
}
//添加子節(jié)點
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;
}
相關文章
C#基于正則表達式實現(xiàn)獲取網(wǎng)頁中所有信息的網(wǎng)頁抓取類實例
這篇文章主要介紹了C#基于正則表達式實現(xiàn)獲取網(wǎng)頁中所有信息的網(wǎng)頁抓取類,結(jié)合完整實例形式分析了C#正則網(wǎng)頁抓取類與使用技巧,需要的朋友可以參考下2017-05-05