I had a similar issue. I'm putting this here for anyone that comes along after, but solved my issue similar to how Ignas Vaitekunas eventually did it.
I used
XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
xgc.setYear(year);
xgc.setMonth(month);
xgc.setDay(day);
xgc.setHour(hour);
xgc.setMinute(min);
xgc.setSecond(second);
xgc.setTimezone(timezone);
Where year, month, day, hour, min, second, timezone are all initially set to DatatypeConstants.FIELD_UNDEFINED
.
I pull values from a formatted text field that's displayed to the user as ' - - T : : Z'. The user fills in what information they have, I split and parse the string and if I have a value for the timezone (or second, or minute, or hour etc) I set it, if not it gets fed to xgc as and undefined field. Then the XML Gregorian Calendar will print out only what values aren't undefined.