Run script before run

I am writing a XML parser/Code generator for Unity 3.0, and I would like it to be automatically ran whenever either the play button is pressed, and when the project is built. Is there a way to do this?

One idea is to create a custom editor class and add the operation as a callback function to EditorApplication.playmodeStateChanged

Good Luck!