返回xml元素的Xquery

返回xml元素的Xquery,xml,xquery,Xml,Xquery,我有一个XML文件,它的开头如下: <tpinfos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schemaTP.xsd"> <jour id="lundi"> <salle id="A11"> <creneau debut="8:00" fin="10:00"> <f

我有一个XML文件,它的开头如下:

<tpinfos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schemaTP.xsd">
<jour id="lundi">
    <salle id="A11">
        <creneau debut="8:00" fin="10:00">
            <formation>M1 Info</formation>
            <enseignant>ME Voge</enseignant>
            <matiere>ACT</matiere>
        </creneau>
        <creneau debut="10:00" fin="12:00">
            <formation>M1 Miage</formation>
            <enseignant>AC Caron </enseignant>
            <matiere>ED</matiere>
        </creneau>
        <creneau debut="12:00" fin="13:30">
            <formation>M1 Info</formation>
            <enseignant>ME Voge</enseignant>
            <matiere>ACT</matiere>
        </creneau>
        <creneau debut="15:20" fin="17:20">
            <formation>M1 Info</formation>
            <enseignant>ME Voge</enseignant>
            <matiere>ACT</matiere>
        </creneau>
    </salle>
我的问题是我应该返回的数据类型,即“元素(tpinfos)”。 由于这个数据类型,我所有的尝试都失败了,我真的不知道应该如何做才能不出错

我最后一次尝试是:

declare function local:filtreFormation($f as xs:string) as element(tpinfos)
{
  for $cr in doc("planningTP.xml")/jour/salle/creneau
  where $cr/formation = $f
    return element tpinfos {$cr}
};
但它返回错误“匹配所需序列类型的错误事件”


谁能给我解释一下有什么问题吗?

函数返回的基数与结果不匹配。目前,它希望总是返回一个(并且只有一个)
tpinfos
元素。如果返回一个空序列或多个元素,这将与签名不匹配,并将导致错误

将函数声明更改为允许零到多个
tpinfos
元素:

declare function local:filtreFormation($f as xs:string) as element(tpinfos)*
declare function local:filtreFormation($f as xs:string) as element(tpinfos)*