Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to specify a decimal or date format in a XSD model

Status
Not open for further replies.

bart58

Programmer
Dec 16, 2002
4
0
0
FR

Hi ,

i'm very new in XML and i have a few questions. I only want to create an xml file to send data to some customer.

I defined a xsd model to validate my xml files and i was wondering how to :

1 - Specify that the decimal character is ',' instead of '.'

2 - Specify that the date format is , for exemple, 'DD/MM/YYYY' instead of 'DD-MM-YY' .

I am using <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>

I am sure it is very simple but i don't know how yet ...
 
Dates in XML are ISO-8601, their format is:
yyyy-mm-ddThh:nn:ss
or
yyyy-mm-ddThh:nn:ssZ (if UTC/GMT)
or
yyyy-mm-ddThh:nn:ss+nn:ss (for positive timezone offset)
or
yyyy-mm-ddThh:nn:ss-nn:ss (for negative timezone offset)

Numbers in XML that have decimal indicators (points or commas) are of the &quot;xs:Float&quot; datatype, which use the point symbol (1234.56).

Since it sounds like you want your values localized (looks like German to me), you'll need to use a xs:String datatype, which will allow almost anything. Your application would then be responsible for ensuring/validating correct format. I would urge the customer to use correct XML datatypes, as it will cause them fewer problems in the long run.

Chip H.
 
Oops - made a mistake. The timezone offset is in hours and minutes, not minutes and seconds. Should be:

yyyy-mm-ddThh:nn:ss+hh:nn (for positive timezone offset)
or
yyyy-mm-ddThh:nn:ss-hh:nn (for negative timezone offset)

Also forgot to mention you can include a tenths of a second field. You might also want to take a look at RFC-3339:
Code:
 From RFC-3339: Date and Time on the Internet: Timestamps

   date-fullyear   = 4DIGIT
   date-month      = 2DIGIT  ; 01-12
   date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                             ; month/year
   time-hour       = 2DIGIT  ; 00-23
   time-minute     = 2DIGIT  ; 00-59
   time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                             ; rules
   time-secfrac    = &quot;.&quot; 1*DIGIT
   time-numoffset  = (&quot;+&quot; / &quot;-&quot;) time-hour &quot;:&quot; time-minute
   time-offset     = &quot;Z&quot; / time-numoffset

   partial-time    = time-hour &quot;:&quot; time-minute &quot;:&quot; time-second
                     [time-secfrac]
   full-date       = date-fullyear &quot;-&quot; date-month &quot;-&quot; date-mday
   full-time       = partial-time time-offset

   date-time       = full-date &quot;T&quot; full-time

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top