I recently went through this. While I didn't have to create an XML doc for the sitemap, I just needed to list the page urls. With some simple editing, you can modifiy the following script to generate XML instead of a straight list.
source: https://pageditor.wordpress.com/2015/03/20/list-of-urls/
<%@ Page Language="c#" AutoEventWireup="true" Debug="true" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>List of URLs</title>
</head>
<body>
<script language="C#" runat="server">
string domain = "http://mysite.com";
int count = 0;
void Page_Load(object sender, System.EventArgs e)
{
Sitecore.Data.Database web = Sitecore.Configuration.Factory.GetDatabase("web");
var home = web.GetItem("/sitecore/content/MySite/home");
var pages = GetChildren(home);
Response.Write(pages);
Response.Write("Total # of pages: " + count.ToString());
}
private string GetChildren(Item home)
{
string result = "";
if (!home.HasChildren) return "";
var childList = home.GetChildren();
foreach(Item item in childList)
{
if (DoesSitecoreItemHavePresentation(item))
{
result += domain + Sitecore.Links.LinkManager.GetItemUrl(item) + "<br />";
count++;
}
result += GetChildren(item);
}
return result;
}
public bool DoesSitecoreItemHavePresentation(Item item)
{
return item.Fields[Sitecore.FieldIDs.LayoutField] != null
&& item.Fields[Sitecore.FieldIDs.LayoutField].Value != String.Empty;
}
</script>
</body>
</html>