Date validation in xsd

1
I've generated a xml file with mendix and i'm trying to import this in another mendix application. I'm getting xsd validation errors on a date field. A date field with value: 2011-01-17T23:00:00.000Z causes an xsd validation error during de xml to domain mapping in a mendix application. How can a date field generated by mendix be invalid in another mendix app? Edit: I know what happened. The date in the xml is a datetime value. The date in the other application had a xsd:date type. So that's why the validation error occurred. I've fixed it by exporting the date value as a string with formatDate. This worked for me.
asked
2 answers
2

There's a known issue with xsd:date elements, they're generated as datetime and thus cannot be imported (at least with data validation) by mendix. We hope to fix this soon.

Note that datetime elements always work correctly.

If you want to be kept updated on when this will be fixed, file a bugreport in our support portal.

answered
0

The date storage has changed somewhere between 2.4.x and 2.5.1.1. To solve this you can use custom MF mappers. You can use the following javacode if you want to send a date from 2.5 to 2.4.5 (datetime is the argument, a DateTime, and the function returns a string):

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 
    format.setTimeZone(TimeZone.getTimeZone("UTC")); 
    return format.format(datetime);

On the 2.4.x side you can convert the String back to a datetime using a java action with:

    Date val = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.getDefault()).parseDateTime(date).toDate(); 
    return val;

(So instead of using datetimes, strings are used. So you need to add an additional (virtual) attribute for this in your domain model, to store the converted date).

answered