怎么递归读写Web.sitemap文件??

解决方案 »

  1.   


    System.Xml.XmlDocument dom = new System.Xml.XmlDocument(); 
                dom.LoadXml(xml); 
                foreach (System.Xml.XmlNode node in dom.ChildNodes) 
                {  
                  if(node.Name !="xml") 
                    Response.Write(GetNode(node));  
                } 
            }         string GetNode(System.Xml.XmlNode node) 
            { 
                string str = node.InnerText; 
                if (node.HasChildNodes) 
                { 
                    str = ""; 
                    foreach (System.Xml.XmlNode n in node.ChildNodes) 
                    { 
                        str += GetNode(n); 
                    } 
                } 
                return str; 
            }C#递归读写XML文件
      

  2.   

    我现在想吧这个文档读出来
      需要递归循环取值  绑定到前台  请高手指教下!!!
    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
      <siteMapNode url="default.aspx" title="网站"  description="">
        <siteMapNode url="a.aspx" title="试试" description="">
          <siteMapNode url="b.aspx" title="的" description=""></siteMapNode>>
        </siteMapNode>
        <siteMapNode url="c.aspx" title="多少" description="">
          <siteMapNode url="d.aspx" title="大事" description=""></siteMapNode>
        </siteMapNode>
        <siteMapNode url="f.aspx" title="奥斯丁" description="">
          <siteMapNode url="g.aspx" title="奥飞" description=""></siteMapNode>
        </siteMapNode>
        <siteMapNode url="j.aspx" title="二二五" description="">
          <siteMapNode url="g.html" title="阿斯旺">
            <siteMapNode url="u.aspx" title="发" description=""></siteMapNode>
          </siteMapNode>
          <siteMapNode url="t.html" title="发送" description="">
            <siteMapNode url="y.aspx" title="热" description=""></siteMapNode>
          </siteMapNode>
        </siteMapNode>
      </siteMapNode>
    </siteMap>
      

  3.   

    要是主动去读那个文件, 就没必要使用那个文件了那个是为 sitemap 用的, 你用相关的类型访问就行了sitemap 的数据源可以是 xml, 也可以编写自己的数据提供者
      

  4.   

    Sorry,I can't follow you.
      

  5.   

    有  SiteMapPath 控件直接绑定 
      

  6.   

    五、利用代码工具自动生成Sitemap文件
        制作过程说明:(L-BLOG为例)
      将以下代码复制到本地存为sitemap.asp或sitemap.php,上传到你的服务器网站的根目录下,运行一下就可以在你指定的目录中(建议最好是指定为根目录)自动生成一个sitemap.xml文件了。
        asp程序代码: 引用内容
    <!--#include file="commond.asp" -->
    <%
    Response.Buffer = True
    With Response
    .Expires = -1
    .AddHeader "Pragma","no-cache"
    .AddHeader "cache-ctrol","no-cache"
    End With
    %>
    <!--#include file="include/function.asp" -->
    <%
    Server.ScriptTimeout=50000Dim str,objStream
    str = "<?xml version='1.0' encoding='UTF-8'?>" & vbcrlf
    str = str & "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"">" & vbcrlfstr = str & getfilelink & vbcrlf
    str = str & "</urlset>" & vbcrlfSet objStream = Server.CreateObject("ADODB.Stream")
    With objStream
    .Open
    .Charset = "utf-8"
    .Position = objStream.Size
    .WriteText=str
    .SaveToFile server.mappath("sitemap.xml"),2 '生成的XML文件名
    .Close
    End With
    Set objStream = NothingIf Not Err Then
       Response.Write("<head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /><title>已经成功生成站点地图</title></head><h4>已经成功生成站点地图。</h4><br><br><a href=http://www.coosuo.com/default.asp>返回首页</a> |  <a href=sitemap.xml>查看地图</a>")
       Response.End
    End IfFunction getfilelink()
       SQL="Select L.log_ID,L.log_Title,l.log_Author,L.log_PostTime,L.log_Content,L.log_IsShow,L.log_DisSM,L.log_DisUBB,L.log_DisIMG,L.log_AutoURL,L.log_AutoKEY,C.cate_Name FROM blog_Content AS L,blog_Category AS C Where C.cate_ID=L.log_cateID orDER BY log_PostTime DESC"
       Dim RS
       Set RS=Server.CreateObject("ADODB.RecordSet")
       RS.Open SQL,Conn,1,1
       IF RS.EOF AND RS.BOF Then
          Response.Write("<url></url>")
       Else
          Do While NOT RS.EOF
              getfilelink = getfilelink & "<url><loc>"&SiteURL&"/blogview.asp?logID="&RS("log_ID")&"</loc><lastmod>"&DateToStr(RS("log_PostTime"),"y-m-dTH:I:S")&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
              RS.MoveNext
          Loop
       End IF
    RS.Close
    Set RS=Nothing
    Conn.Close
    Set Conn=Nothing
    End Function
    %>