Question:

How to recursivly traverse through SG's and pages using Content delivery API?

Lucy: 5 days ago

I am trying to generate a sitemap.xml file of all the pages that are published to the Broker. Can this be achieved if I use the content delivery API? Can I recursively traverse through the SGs and pages to get the URL of the page?

Answer:
Madison: 5 days ago

There is a good article by Nickoli Roussakov (http://www.tridiondeveloper.com/web-sitemap) that pretty much gives you the code you need to generate a sitemap file by traversing through SGs and Pages. You simply need to add a TBB to your Page Template which will generate your sitemap.

However, in most cases, business rules tend to handle other logic through Page or SG Metadata which can be appended as attributes to each siteMapNode. But, to do this you will need to extend the code to meet your needs.

On a side note, I'd just like to add (depending on the amount of SGs and Pages you have), the sitemap xml file could become really large, becoming quite time consuming to publish as you will be updating the file on every publish/unpublish. Assuming you haven't yet decided on an approach to take, I would have a read of this post (https://tridion.stackexchange.com/questions/381/what-are-the-best-practices-to-manage-the-sitemap-for-a-tridion-website) which discusses alternative ways to generate a sitemap.