2

考虑以下检查空日期的代码:

declare xqse function tns:isEmptyDate($dob as xs:date) as xs:boolean {
    if(empty($dob)) then {
    }
}

执行时,为什么会在 ALDSP 中出现以下错误:

weblogic.xml.query.exceptions.XQueryDynamicException: {err}XP0021: "": can not cast to {http://www.w3.org/2001/XMLSchema}date: error: date: Invalid date value: wrong type:

4

4 回答 4

2

OK, I've had a look at this and I think you'll be able to run your query by defining your function as

declare function tns:isEmptyDate($dob as xs:date?) as xs:boolean

Note the ? after the type - it means that the argument may be the empty sequence.

I tested this out in Oxygen, using Saxon-B... sorry, I don't have access to the software you're using.

Here's my function definition.

declare function tns:isEmptyDate($dob as xs:date?) as xs:boolean {
    let $empty := if (empty($dob))
        then true()
        else false()
    return $empty
};

Running against this file:

<?xml version="1.0" encoding="UTF-8"?>
<datetime>2002-09-24</datetime>

returns true, and running against this file:

<?xml version="1.0" encoding="UTF-8"?>
<dontmatch>2002-09-24</dontmatch>

returns false.

Running the same function without the questionmark, on the second document, errors with:

Severity: error. Description: An empty sequence is not allowed as the first argument of tns:isEmptyDate()

于 2009-06-15T16:22:41.217 回答
1

在类型声明后用问号或星号试​​试这个。

例如,

$dob as xs:date 表示 $dob 是 1 个项目的序列(类型为 xs:date)

$dob 作为 xs:date? 表示 $dob 是 1 项或无项的序列(每个项的类型均为 xs:date)

$dob as xs:date* 意味着 $dob 是一个没有或多个项目的序列(每个项目都是 xs:date 类型)

于 2009-06-17T16:10:51.843 回答
1

使用函数empty()而不是编写自己的函数。如果序列的计数为零,则 Empty 将返回 true,其中xs:date?可以是长度为零或一的序列。

于 2012-05-18T16:58:53.910 回答
0

我只修改了 XQuery,但我怀疑正在生成错误,因为函数签名($dob as xs:date)需要日期类型,而您正在传递其他内容,例如空值。

于 2009-06-15T16:01:29.723 回答