xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Springer, Ian P." <ian.sprin...@hp.com>
Subject RE: DateTime format question
Date Thu, 29 Jul 2004 15:44:06 GMT
Hi Radhakrishnan,

Your dateTime string is indeed malformed. The format for the timezone
portion is "+|-nn:nn" - yours is missing a leading zero between the '+'
and the '5'. So the correct string would be
"1979-10-12T10:10:10.10+05:30".

Attached is a Java DateFormat impl that can be used to validate XSD
dateTimes.

Regards,
Ian 

| -----Original Message-----
| From: Radhakrishnan J [mailto:radhakrishnan.j@tavant.com] 
| Sent: Thursday, July 29, 2004 9:24 AM
| To: xmlbeans-user@xml.apache.org
| Subject: DateTime format question
| 
| Hi,
| 
| Whats wrong with this code snippet ?
| 		
| 		XmlOptions options = new XmlOptions();
| 		Collection errors = new ArrayList();
| 		XmlDateTime dateTime =
| XmlDateTime.Factory.parse("<xml-fragment>1979-10-12T10:10:10.1
0+5:30</xml-fr
| agment>");
| 		System.out.println(dateTime);
| 		dateTime.validate(options);		
| 		System.out.println(errors);
| 
| This code prints
| 
| <xml-fragment>
| 1979-10-12T10:10:10.10+5:30
| </xml-fragment>
| [error: Date value is malformed: 1979-10-12T10:10:10.10+5:30]
| 
| I rigged it up the xml fragment having read the XML Schema -Datatypes
| specification. Am I missing something ? Also, I had a problem 
| with the date
| formats. One of our schema components is a date-time type 
| definition defined
| as follows :
| 
| 	<xs:simpleType name="Date">
| 		<xs:restriction base="xs:date">
| 			<xs:pattern value="\d\d\d\d-\d\d-\d\d"/>
| <!-- restrics the year to 4 digit and does not accept 
| time-zone info -->
| 		</xs:restriction>
| 	</xs:simpleType>
| 	<xs:simpleType name="DateTime">
| 		<xs:restriction base="xs:dateTime">
| 			<xs:pattern
| value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(Z|(\+|-)\d\d:\
| d\d)"/>	<!--
| restricts the year to 4 digit and does not accept fractional 
| seconds -->
| 		</xs:restriction>
| 	</xs:simpleType>
| 	<xs:simpleType name="DateTimeAny">
| 		<xs:union memberTypes="Date DateTime"/>
| 	</xs:simpleType>
| 
| The XmlBean generated java type for DateTimeAny is 
| 'java.util.Calendar'.
| When a 'Calendar.getInstance()' is passed as an argument to 
| the setter, it
| triggers the followoing validation error :
| 
| [error: Union '2004-07-29+05:30' does not match any members 
| of DateTimeAny
| in namespace http://www.openapplications.org/oagis]
| 
| Following one of the earlier mail threads on this topic, I 
| resorted to the
| 'Calendar.clear(Calendar.ZONE_OFFSET)' before passing the 
| calendar to the
| setter. This makes things work fine. However, I would like to 
| retain the
| time zone information. Got some questions :
| 
| (a) How is the string '2004-07-29+05:30' arrived at ? At the 
| outset seems
| like a 'xs:date' type although the calendar instance has all 
| information to
| construct a 'xs:dateTime' as well.
| (b) Are the above extensions OK ? These schemas have been 
| defined by another
| workgroup. Based on the feedback to this question, I might 
| negotiate to
| remove the restrictions ( I still don't know why they are 
| there in the first
| place ).
| (c) If not, How can I get rid of the validation error ?
| 
| Thanks,
| Radhakrishnan 
| Extn  367
| 
| http://kwiki-infra.india.tavant.com/kwiki/
| 
| 
| 
| - 
| ---------------------------------------------------------------------
| To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
| For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
| Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
| 
| 

Mime
View raw message