Both the game and lua files use the .lua language. Micromacro is for executing lua scripts like the rombot. .xml files have xml code in them and are basically just a way to store information using tags. It can have lua in between the xml tags. The lua reference can be found here.
http://www.lua.org/manual/5.1/
If you create a function it needs to be put somewhere so that it gets loaded and becomes available for you to use like you said
<waypoint>DoSomething()</waypoint>
You can put functions in a number of places.
If you want to make a function that you will use in many scripts, you can place it in the "userfunctions.lua" file(you will have to create it if it doesn't already exist).
If you want to create a function that you will share, you can create a file for it in the "userfunctions" folder. The name of the file should be prefixed with "userfunction_", eg. "userfunction_myfunction.xml".
If you want to create a function for a specific need in a particular waypoint file you can put it in the onLoad section of the waypoint file.
There are probably a few other places you can put them but you get the idea.