[xsd-users] Re: Using xml_schema::date

Boris Kolpackov boris at codesynthesis.com
Wed Jun 4 04:16:56 EDT 2008


Hi Jullien,

Jullien Patrick <pjullien at sopragroup.com> writes:

> I assume that some changes have been made about datetime support in XSD,
> I have an xml schema containing some date attributes and the mapping
> classes generated with 3.1.x version of XSD is pretty much different
> that ones generated by 3.0.x

Right. Here is a fragment from the NEWS file:

New implementations of the XML Schema date/time types (date, dateTime,
duration, gDay, gMonth, gMonthDay, gYear, gYearMonth, and time) that
represent the information in the numerical form.


> You have added a date-time.hxx file into xsd/cxx/tree directory
> containing classes (timezone, date, date_time, etc.) that were defined
> in types.hxx, but the old xml_schema::date(string) constructor is no
> more available. Can you please give me the best practices for using this
> new type ? 

The old implementation was just a glorified string. The new one
uses numeric representation. The xml_schema::date class now has
the following two constructors:

date (int year, unsigned short month, unsigned short day);
date (int year, unsigned short month, unsigned short day,
      short zone_hours, short zone_minutes);

So you would create a date instance like this:

date today (2008, 6, 4);
date tomorrow (2008, 6, 5, -2, -30); // GMT-2:30

For more information about the new date/time types see Section 2.5,
"Mapping for Built-in Data Types" in the C++/Tree Mapping User Manual:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.5


> How one should parse strings for constructing these new objetcs to
> conform to [YYYY-mm-dd] standard xml date-format string (and go back to
> string from an xml_schema::date object)?

While our intention was for the user to use the numeric representation
as shown above, you can use the parsing constructor and ostream operator
(requires the --generate-ostream option) to achieve this:

date today ("2008-06-04", 0);

std::ostringstream ostr;
ostr << today;
std::string today_str = ostr.str ();

Boris




More information about the xsd-users mailing list