1
votes

i have a XML file which begins like this :

<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>

I am supposed to take every < creneau > that will match the < formation > with the parameter of this function :

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

My problem is the dataType I am supposed to return, the "element(tpinfos)". All my attempt failed because of this datatype, i really don't get how i am supposed to do it without getting an error.

My last try was :

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}
};

But it returns the error "Wrong occurrence to match required sequence type"

Can anyone explain to me what is wrong please?

1

1 Answers

1
votes

The cardinality of the returned sequence type of your function does not match your result. Currently, it is expecting to always return one (and only one) tpinfos element. If it were to return an empty sequence, or multiple elements, that would not match the signature and would result in an error.

Change your function declaration to allow for zero to many tpinfos elements:

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