There is a useful sample in the Sitefinity Toolkit
and a helpful blog entry here
A second example you can find in the SDK which has a sample for a Sitemap module.
When retrieving pages the api delivers all pages. Also if you have a multisite environment.
For that you can use some code like that to get the root node of your site:
// get the correct site
MultisiteContext mc =
ISite site = mc.CurrentSite;
// get the id of the root site
Guid rootId = site.SiteMapRootNodeId;
// append pages to the sitemap
// get a page manager
PageManager pageManager = PageManager.GetManager();
// get the pages
IQueryable<PageData> pages = pageManager.GetPageDataList().Where(pData => pData.Status == ContentLifecycleStatus.Live);
In the query you can put in some additional filtering...
When stepping through the pages you can check if the pages have the same root node:
(page.NavigationNode.RootNodeId == rootId)
@Stefani: The feature should care for multi site environments and should also cover ignore lists or use a flag in pages telling the sitemap if a page should not be in the xml sitemap.