Help in dateTime Schema pattern

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nerds
    New Member
    • Nov 2007
    • 3

    Help in dateTime Schema pattern

    I declared one element in my XML Schema by restriction base= "xs:dateTim e", with the Pattern value as dd/mm/yyyy, when I validate the
    XML with this format, it shows the error that the
    give value is not valid, so my question is how to change the date format in
    XML Schema ??

    Thanks
    Nerd
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Originally posted by Nerds
    I declared one element in my XML Schema by restriction base= "xs:dateTim e", with the Pattern value as dd/mm/yyyy, when I validate the
    XML with this format, it shows the error that the
    give value is not valid, so my question is how to change the date format in
    XML Schema ??

    Thanks
    Nerd
    xs:datetime is a specific format, being: 0001-01-01T00:00:00 which corresponds to YYYY-MM-DDThh:mm:ss

    I'd use a pattern restriction like so:
    [code=xml]<xs:simpleTyp e>
    <xs:restricti on base="xs:string ">
    <xs:pattern value="([0-9]{2}/){2}[0-9]{4}"/>
    </xs:restriction>
    </xs:simpleType>[/code]

    Note, this pattern does not validate number of days in a month etc. If you want that, you need a more complex pattern. eg see http://www.thescripts.com/forum/thread728713.html

    Comment

    • Nerds
      New Member
      • Nov 2007
      • 3

      #3
      Thanks for the help i will try like this..

      thanks
      nerds
      Originally posted by jkmyoung
      xs:datetime is a specific format, being: 0001-01-01T00:00:00 which corresponds to YYYY-MM-DDThh:mm:ss

      I'd use a pattern restriction like so:
      [code=xml]<xs:simpleTyp e>
      <xs:restricti on base="xs:string ">
      <xs:pattern value="([0-9]{2}/){2}[0-9]{4}"/>
      </xs:restriction>
      </xs:simpleType>[/code]

      Note, this pattern does not validate number of days in a month etc. If you want that, you need a more complex pattern. eg see http://www.thescripts.com/forum/thread728713.html

      Comment

      Working...