Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#380 Error when cast used in XQuery attribute constructor

v8.5
closed
Michael Kay
5
2012-10-08
2005-08-04
Michael Kay
No

The spurious error message

Cannot cast to xdt:anyAtomicType

occurs when a "cast as" expression is used within an
enclosed expression in a direct attribute constructor,
for example

<e a="{'1' cast as xs:integer}"/>

(the reason for this is that such enclosed expressions
must be initially processed without knowledge of the
in-scope namespaces, since namespace declarations can
follow attributes. So there is a "scan only" mode of
parsing, and in this mode any reference to an atomic
type name is treated temporarily as a reference to
xdt:anyAtomicType. But a cast to xdt:anyAtomicType is
not permitted, and Saxon 8.5 is checking for this error
during the "scan only" phase of processing).

Source fix: at line664 of
net.sf.saxon.expr.ExpressionParser.java, change

if (scanOnly) {
return Type.ANY_ATOMIC_TYPE;
}
to

if (scanOnly) {
return Type.STRING_TYPE;
}

Discussion

  • Michael Kay
    Michael Kay
    2005-08-06

    Logged In: YES
    user_id=251681

    The follow-up to this exposes another problem. Essentially
    there is too much semantic processing being done when
    enclosed expressions are parsed in scan-only mode.
    Specifically, function calls are being fixed up to the
    corresponding function declarations, which can lead to
    spurious type errors later. The following patch fixes this:

    In net.sf.saxon.expr.ExpressionParser before the line 1715
    which reads

    Expression[] arguments = new Expression[args.size()];

    add

        if (scanOnly) {
            return StringValue.EMPTY_STRING;
        }