Hi John,
Thanks a lot for the detailed explanation. I've coded up most of the XPath
evaluation logic. I will send in a patch really soon. However while carrying
out some test runs I ran into a couple of issues with type validators.
1. DoubleDV cannot compare decimals and other numeric objects. It attempts
to cast the arguments into XDouble type which causes a ClassCastException to
be thrown. This is bit of a problem since according to the XPath 2.0 spec
most of the numeric comparisons will be carried out using the Double data
validator. So if we have a test like "@attr > '5' cast as xsd:integer" where
the attribute value is a numeric the XPath evaluator will fail with the
above exception. However as a simple workaround soon after performing the
cast operation I cast the resulting value back to double. This is ok since
casting a numeric into double does not cause any data to be lost or added.
But I believe there should be a better way than that.
2. I'm having trouble performing casts of the following nature.
5.2 cast as xsd:integer
This is a double to integer cast and I use the validate method of the
integer simple type decl (XSSimpleTypeDecl) to perform the cast. But it
throws an exception saying '5.2' is not a valid value for integers. I also
tried to carry out this cast as a string to integer cast but still had no
luck. It seems the type implementations do not allow castings which has a
potential to lose data. (may be this is a feature and not a bug?)
Any thoughts how I can get around these two issues? Other than these two
pitfalls everything seem to work. I'll submit a patch as soon as possible to
get some early feedback.
Thanks
Best Regards,
HIranya
On Fri, Dec 26, 2008 at 6:11 AM, John Chan <[email protected]> wrote:
>
> Have a look in the XPath 2.0 spec Appendix B, Type Promotion and Operator
> Mapping [1] and XQuery 1.0 and XPath 2.0 Functions and Operators spec
> section 17, Casting [2]. "If an operator in the operator mapping tables
> expects an operand of type ET, that operator can be applied to an operand
> of
> type AT if type AT can be converted to type ET by a combination of type
> promotion and subtype substitution."
>
> 2. For expressions such as 5 = '5', it is doing a comparison between a
> numeral and a string. I'm not sure what is supposed to happen in this
> case,
> as decimal is not derived from string and vice versa, and the type
> promotion
> rules do not cover this case. It looks like the syntax is correct but the
> semantics is not allowed. I'm guessing an error should be thrown, perhaps
> during/after the expression parsing phase, as you should know the type of
> each value in the expression and can determine whether the evaluation
> between two types is valid, or just do it in the evaluation phase as the
> expression is being evaluated.
>
> 3. I believe the numeric literal 5 is of type decimal (I think I read
> somewhere that numeric literals are type decimal). Since the first operand
> is a decimal and the second operand is an integer, and integer is derived
> from decimal, you don't have to do any casting – just use the decimal
> validator's compare method to compare both decimal and integer (this is a
> subtype substitution).
>
> 4. You would first cast the decimal 5.1 to an integer, then the string
> literal 5 to a double and then promote the first operand from an integer to
> a double (Type promotion 1b, a value of type decimal or any type derived
> from decimal, i.e. integer, can be promoted to either double or float.) and
> then compare the two operand's values. You must perform all casts defined
> explicitly in the expression as the casts may fail, and then do implicit
> type promotions or subtype substitutions as necessary to perform the
> comparison.
>
> [1] http://www.w3.org/TR/xpath20/#id-type-promotion-and-operator-mapping
> [2] http://www.w3.org/TR/xquery-operators/#casting
>
> --
> View this message in context:
> http://www.nabble.com/Type-Alternatives%3A-XPath-Evaluation-tp21155338p21170909.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]
>
>