Hi John,

Thanks again for the reply. Please see my comments in-line.

On Sat, Dec 27, 2008 at 12:49 AM, John Chan <[email protected]> wrote:

>
> 1. For "@attr > '5' cast as xsd:integer", @attr will be cast into
> xsd:double.
> You cannot just use the DoubleDV to compare an integer and a double.
> According to the type promotion rules, you have to cast the integer to a
> double and then compare the doubles.  There is no better way than this.
>  You
> have to first perform all explicit casts defined in the expression.  Think
> about what happens for "@attr > '5.2' cast as xsd:integer".  If you do not
> perform the integer cast, and directly do a comparison, you will be testing
> whether the attribute value is greater than 5.2 and not 5.  And according
> to
> type promotion and subtype substitution rules, when you compare a double to
> an integer, you have to cast the integer to a double.


So it seems my simple workaround is the way to go :). That is to promote the
numeric values into double after performing the explicit cast.


>
>
> 2. Yeah, the validate method doesn't really perform casts as you expect.
>  As
> the method name implies, it only validates whether the value is valid for
> the data type, nowhere does it say it performs casting.  A simple solution
> is to perform checking before validation – check if the resulting type is
> integer, if so, validate the value without any decimals.  There are other
> cases like this, like the date types, casting from a double to a float,
> float to an integer, etc.


So I guess I have to first check the type specified in the cast expression
and do some adjustments to the value as necessary. For an example if the
expression is '5.2' cast as xsd:integer I'll have to adjust the value to 5
before calling the validate method because the casted type is integer.

Are there any general methods/classes in Xerces which provide this
functionality? As you know there are lot of data types in XML Schema and
implementing type checking logic for each of them will be a lot of work.

Thanks

Best Regards,
Hiranya


>
>
> Regards and Merry Christmas,
> John
> --
> View this message in context:
> http://www.nabble.com/Type-Alternatives%3A-XPath-Evaluation-tp21155338p21177809.html
> Sent from the Xerces - J - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to