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.
I will use a similar but slightly different approach to what @Anumap suggested, because I like to keep things decoupled. So, I would create two separate components in Tridion which hold the audio and video sitemap and update them on every publish of a page of type audio or video and then publish the same only if there is a change in the SiteMap.

I will use publish event system asynchronous method of transaction save to get the transaction, find the page object, identify if needed to update sitemap or not and will publish only if there is a new addition to the sitemap components. The method is

```
EventSystem.SubscribeAsync<PublishTransaction, SaveEventArgs>

```

This keeps things decoupled and advantage is you publish only when there is a new addition to the sitemap. It will be faster on regular page publish or updates to a page since there will be no change in sitemap, while custom resolver or any other synchronous event will atleast check to see if it needs to make update or not on every publish transaction and will add time to every publish, be it new or existing page publish with modifications.