Validate MySQL datetime format with relax-ng

Key for validating string content with relax-ng is to user the “pattern” parameter.

A MySQL datetime format is as follow:

2009-01-13 13:25:06 # output of 'select NOW();'

Corresponding relax-ng validation schema is:

<!-- define mysql datetime format content -->
<define name="global.mysql_datetime">
<data type="string"><param name="pattern">[0-9]{4}(-[0-9]{2}){2} [0-2][0-9](:[0-5][0-9]){2}</param></data>
</define>

Now you can simply call it in your relax-ng document using <ref name=”global.mysql_datetime”>, for example to ensure <creation_date> node has mysql datetime formated content, you could use:

<element name="creation_date"><ref name="global.mysql_datetime"/></element>

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...