I think your itinerary is fine, with some day-to-day tweaks as suggested above. I would get that Xian-BJ ticket the day you arrive in Shanghai, after you check in to your hotel. If the hotel is willing for a reasonable surcharge like RMB 50 or so, have them go get it. Otherwise, have the concierge write down the particulars in Chinese, then give you directions to the nearest remote train ticketing office which is likely within 5-10 minutes' walk from the hotel. Take your passport with you to buy. You don't need to fool around with English windows, going to the station, etc.
When you get to Shanghai, call up to the Beijing hostel to confirm the dates their GW tour is going out for the actual days you'll be in BJ, that will help you craft your specific daily plan in BJ. Might as well reserve your place while on the phone, they'll probably be OK with actual payment once you get to BJ.