users@jaxb.java.net

Re: Customaziation and validation

From: Sriram Thyagarajan <Sriram_Thyagarajan_at_KEANE-NNE.com>
Date: Thu, 10 Apr 2003 12:29:19 -0400

>Whether javaType is present or not or whether your converter can handle
values or not are irrelevant for the validation; all it matters is
whether something is valid according to the schema spec.

Woudn't it be valid according to the Schema specs ? The schema defines an
element as type SimpleType and as the one which has different conversion
rules ?

So does this mean that if I have validation turned on, then Conversion using
other methods cannot be done ?

Just curious, one solution I can think in my situation is to catch that
event and discard it as if it did not happen...

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            jxb:version="1.0">
<xsd:simpleType name="Date_CCYYMMDD">
  <xsd:annotation>
     <xsd:appinfo>
        <jxb:javaType name="java.util.Calendar"
        parseMethod="XMLDataConvertor.parseDateToCalendar"
        printMethod="XMLDataConvertor.parseCalendarToDate" />
     </xsd:appinfo>
  </xsd:annotation>
  <xsd:restriction base="xsd:date">
  </xsd:restriction>
</xsd:simpleType>


      <xsd:element name="AccidentDate" type="Date_CCYYMMDD"
        minOccurs="0" maxOccurs="1"/>


-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Thursday, April 10, 2003 9:36 AM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: Customaziation and validation


> All I am trying to do here is to accept dates in YYYYYMMDD (without the
> '-'s) Is there any other easier way to accept date in different format ?

Then you shouldn't declare its XML type as "xs:date". The YYYYMMDD
format is not a valid value for the xs:date type.

Since you turned on the validation, the JAXB RI assumed that you'd like
your input to be validated against your schema per XML Schema spec,
which rejects YYYYMMDD.

Whether javaType is present or not or whether your converter can handle
values or not are irrelevant for the validation; all it matters is
whether something is valid according to the schema spec.

If you want to accept strings that look like date, then the best you can
do is to use something like xs:token and perhaps use a regexp to make it
tight. Maybe [0-9]{8}?

regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com