I'm pretty sure XP is almost solely based on how long you're racing. Don't take my word for it, but I've noticed the longer races give greater XP than the shorter ones (which makes sense). But as I said don't take my word for it
All gold in the special events + all gold in licenses will get you to Level 21 with out any issues. From then on the higher level races give you the most XP.