asp.net C# 生成sitemap.xml 问题?

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:35:38
SiteMap.xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.scmmjy.com</loc>
<lastmod>2009-11-24</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
</urlset>

aspx.cs生成代码如下:

XmlDocument xml = new XmlDocument();
String mapFileUrl = Server.MapPath("~/SiteMap.xml");
xml.Load(mapFileUrl);
//XmlNode RootNode = xml.DocumentElement;
XmlNode RootNode = xml.SelectSingleNode(String.Format("urlset[@xmlns=\"{0}\"]", "

给你一点参考吧~~这是我以前写的一个动态生成站点地图的~~一个简单实例方法~~~~~~你可以看一下~~~注释很清楚
首先前台将Web.SitMap的物理路径传入CreatSiteMap(string path)方法就可以了~[string path=Server.MapPath("~/Web.sitemap");]
其次关于数据库这边我就是通过GetList(string strWhere)提供的DataTable方法来实现的当然这里根据自己需要来设计数据库不过至少要提供Web.SitMap的三个基本属性~~~当然需要更多的自己可以在ChildNodesCreate(ref XmlDocument doc,ref XmlElement t,DataRow row)方法内添加就行了注释的很清楚~~
/// <summary>
/// 查询多条数据
/// </summary>
/// <param name="strWhere">要查询的条件</param>
/// <returns>返回一个DataTbale查询集合</returns>
public DataTable GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from company_title ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}