Question: Our Environment : SDL Tridion 2013 SP1

We are trying to automate sitemap during every page publishing/unpublishing. The requirement is to create two sitemap files (audiositemap.xml/videositemap.xml). While creating content pages, author would choose whether the page type is audio or video in page metadata.

During publishing/unpublishing, if the page type is audio, url needs to be added in audiositemap.xml file. If it is video type page, it should be added in videositemap.xml.

Can anyone suggest if it can be done through event handler, deployer extension or db customization? Or any other better way.

Answer: 
Well, this wouldn't be Tridion if there weren't 15 ways of doing it. My preferred approach for this - given that you already have the sitemap logic built into CM Templates - would be to use a [Custom Resolver](http://docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v1/GUID-F792AB1A-060A-4757-802D-3A2DB18F022D).

While functionally it can achieve the same as an Event, the reason why I would choose this approach is that it would allow you to add the navigation page in question to the *same* publish transaction, resulting in slightly better performance than creating one additional transaction, and - because it's in the same transaction - if for any reason the other page fails to publish, so does the navigation page.
This can be achieved using Event system. Only thing if your sitemap is bigger in size it will have some performance effect. But you can try the following:

1. Write a custom event handler on Page Publish/unpublish and make the phase TransactionCommitted which is suitable for auto publishing trigger. As if the action is a success then only you need to add url in your sitemap and publish it.
2. Apply your logic to set auto publishing of your sitemap xml based on the value selected in your page metadata (audio/video).

You can try something like below: (not tested)

```
Itemfields metaDataFields = new ItemFields(page.Metadata, page.MetadataSchema);
SingleLineTextField yourField = (SingleLineTextField)metaDataFields["FieldName"];
if(yourField.Value == "audio")
{
//publish audio sitemap 
}
//else publish video sitemap if value is video

```

You can refer to this [link](https://tridionwithanupam.wordpress.com/2015/07/08/get-started-with-tridion-event-system/) to get some info on Event System and also see [here](https://docs.sdl.com/LiveContent/web/pub.xql?action=home&pub=SDL%20Web%20Cloud-v1&lang=en-US&docid=GUID-0C340F6B-384C-443B-BDEA-AE6AC16882A4&query=%2B%22event%20phases%22) for the different event phases.

Also check this interesting [link](https://tridion.stackexchange.com/questions/381/what-are-the-best-practices-to-manage-the-sitemap-for-a-tridion-website/384#384) on 'best practices to manage the sitemap for a Tridion website'. Let me know if this helps.