Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Dynamic Sitemap

  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Sitemap

    Hi,

    I need to make a dynamic sitemap for a CMS.

    All pages are stored in a DB.

    I have pulled all info out into these arrays

    PageIds - all pages ids
    PageNames - all page names
    ParentPages - Parent page of corresponding page (id #'s, except 'root' indicating top level page).

    (eg. PageIds[0] is a sub page of ParentPages[0], if ParentPages[0] = 'root' then it is the top, 1st, level)

    I need it to support an infinate number of levels. My guess is that it needs to be done in a loop but can't seem to figure out how get it to work.

    it should look like this:

    Root Page
    -Sub Page
    -Sub Sub Page
    -etc

    Any help or direction is greatly appreciated.
    Asp.Net 1.1 - 20 hrs
    CSS 2.0 - 3 hrs
    XHTML 1.1 - 5hrs
    JavaScript - 5hrs
    Cross-Browser Compatibility - Priceless

  • #2
    New Coder
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is what I have so far. It worked with the first 5 values but as I added more and it got more complicated it has flaws in it.

    Some pointers or direction would be appreciated.

    Thanks,

    Code:
    @ Page Language="C#" Debug="True" %>
    
    <html>
    <head>
     <title>Group Test</title>
    </head>
    
    <body>
     <script language="C#" runat="server">
    
      void Page_Load()
      {
       string Html = "";
       string [] PageIds = new string[10]{"1","2","3","4","5","6","7","8","9","10"};
       string [] PageNames = new string[10]{"Homepage","About Me","Articles","Downloads","Contact Me","page6","page7","page8","page9","page10"};
       string [] ParentPages = new string[10]{"root","1","4","root","2","root","root","6","7","7"};
       int i;
       int j;
       int lvl;
       int indent;
       int currentJ;
       string currentPage = "";
       bool finished = false;
    
       for(i=0;i<PageIds.Length;i++)
       { 
        lvl = 1;
        indent = 0;
        if(ParentPages[i] == "root")
        {
         finished = false;
         Html += "\n\t\t<div style='width:"+indent+"px;float:left'></div>" + PageNames[i] + "<br>";
         currentPage = PageIds[i];
    
         while(!finished)
         {
          finished = true;
    
          for(j=0;j<PageIds.Length;j++)
          {
           if(currentPage == ParentPages[j])
           {
            lvl++;
            indent += 20;
            currentJ = j;
            currentPage = PageIds[currentJ];
            Html += "\n\t\t\t<div style='width:"+indent+"px;float:left'></div>" + 
            PageNames[currentJ] + "<br>";
           }
          }
    
          for(j=0;j<PageIds.Length;j++)
          {
           if(ParentPages[j] == currentPage)
           {
            finished = false;
           }
          }
         }
        }
       }
       Output.Text = Html;
      }
    
     </script>
    
     <form runat="server">
      <asp:Label id="Output" runat="server" />
     </form>
    
    </body>
    </html>
    Asp.Net 1.1 - 20 hrs
    CSS 2.0 - 3 hrs
    XHTML 1.1 - 5hrs
    JavaScript - 5hrs
    Cross-Browser Compatibility - Priceless


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •