On Wed, Feb 24, 2010 at 8:10 PM, KARR, DAVID (ATTSI) <dk068x_at_att.com> wrote:
> DatatypeFactory isn't strictly JAXB-related, but I figure it has a
> strong correlation to use of JAXB.
>
> I'm calling "DatatypeFactory.newXMLGregorianCalendar(String)" and I'm
> storing the result in an element with a restriction on "xs:datetime".
> I'm having trouble getting the formatting correct.
>
> The schema excerpt is as follows:
>
> <xs:restriction base='xs:dateTime'>
> <xs:pattern value='.+T.+Z'/>
> </xs:restriction>
>
> (which seems odd, as this pattern seems to ignore the "date" portion,
> correct?)
No, the date is in the part preceding the letter 'T'.
>
> From the documentation in our schema:
>
> - T is a fixed character, indicating the time section
> - Z is a fixed character, indicating UTC time zone
>
Both correct.
> I've looked at <http://www.w3.org/TR/xmlschema-2/#dateTime-order> (which
> is mentioned in the javadoc for this function), but it hasn't helped me
> solve this problem.
>
> I've tried giving it a formatted date/time value of
> "2010-05-19T01:00:00-08:00", but when schema validation is done, this
> fails to validate. It appears I'm formatting the timezone value
> incorrectly, but I'm not sure what it should be.
>
> I tried simply replacing the "-08:00" portion with "Z", and that
> appeared to pass validation. Is that what's intended here?
Formally, yes. Logically, it may not be, since the value should be in UTC.
Use this factory method:
newXMLGregorianCalendar(int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int timezone)
And set the last argument to zero. Make sure to obtain the correct
values for UTC, e.g. from a GregorianCalendar created like this:
TimeZone tz = new SimpleTimeZone( 0, "UTC" );
GregorianCalendar now = new GregorianCalendar( tz );
You should then get something like
<DateTime>2010-01-24T19:47:44.000Z</DateTime>
-W