JAXB maps any of eight distinct XML Schema date/time types to
XMLGregorianCalendar. When an XMLGregorianCalendar is marshalled by JAXB, the
output format generated by the toXMLFormat() method should be that appropriate
for the original schema type. Currently this may or may not happen correctly,
depending on exactly which fields of the XMLGregorianCalendar have (not) been
populated by the application code.
This problem could be solved by creating a new version of
XMLGregorianCalendar.toXMLFormat(...) that takes as a parameter a QName
representing the target schema type for formatting the output. Populated fields
not relevant to the schema type would be ignored; missing fields required by the
schema type would cause an exception to be thrown.