Support for Windows XP ended on April 8, 2014, and it is unsafe to use a Windows XP computer connected to the Internet.
See, for example:
http://windows.microsoft.com/en-us/windows/end-support-help
http://www.zdnet.com/article/microsoft-security-research-paints-bleak-picture-for-xp-users/
If the computer hardware permits, it would be much better if you could install Windows 7, which will continue to receive security updates from Microsoft until January 14, 2020. Download the Windows 7 Upgrade Advisor, which will give you some idea of whether the hardware is compatible with Windows 7 -- or you can just go to the computer manufacturer's web site and see if Windows 7 drivers are available.
Although Microsoft stopped retail sales of Windows 7 in October 2013, you can still find Windows 7 installation DVDs for sale -- just do your best to ensure that you're purchasing from a reputable vendor (not the least expensive one). You would also have to download Windows 7 drivers for the computer's hardware.
Once you have the installation DVD and the necessary drivers, you would do a "custom install" of Windows 7.
http://www.sevenforums.com/tutorials/1649-clean-install-windows-7-a.html
http://windows.microsoft.com/en-us/windows7/help/upgrading-from-windows-xp-to-windows-7#T1=tab01
Whether you install Windows 7 or stay with Windows XP (which would be OK if the printer isn't going to be connected to the Internet), drivers for the HP Photosmart Premium 310a are available here: http://support.hp.com/us-en/drivers/selfservice/HP---Photosmart-Premium-All-in-One-Printer-series-----C3/4023238/model/4231204
The full package, which includes HP's Photosmart Software Suite, is rather large: 150.6 MB. For basic printing only, you could download the "Basic Driver" file -- only 67.5 MB. In either case, if the computer you're donating is not connected to the Internet, you can download the files on any computer and then copy them to a USB flash drive.