Hi Bob,

Your function is selecting a child element, but it might not exist. Add a 
question mark behind the return type, that should do the trick. element()? 
means that the function returns either one element or none. Or in other words a 
sequence of elements with a size of either one or zero.

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.


> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Runstein, Robert E. (Contr) (IS)
> Sent: donderdag 23 april 2009 21:24
> To: [email protected]
> Subject: [MarkLogic Dev General] Coercion error passing
> element to function
>
> Hi,
>
> I am trying to create units tests for my functions and have
> encountered an error when I attempt to pass an element to the
> function.
>
> I've omitted the namespace declarations from the example for brevity.
>
> The function defintion is:
>
> declare function mine:doSomething($item as element()) as element() {
>         return $item/ns:someElement
> };
>
> This works fine when invoked with $item obtained from a
> string version of a SOAP document passed in declared as follows:
>
> declare variable $source external;
> let $item :=
> xdmp:unquote($source)/SOAP-ENV:Envelope/SOAP-ENV:Body/ns:item
> let $result := mine:doSomething($item)
> return $result
>
> The problem is when I attempt to call the function from a
> unit test where I construct a shorter document like
>
> let $item := xdmp:unquote("<ns:item
> xmlns:ns="http://urn:my:namespace";><ns:subItem>text</ns:subIte
> m></ns:item>") /ns:item
>
> let $result := mine:doSomething($item)
> return $result
>
> I get the following error
>
> [1.0-ml] XDMP-AS: (err:XPTY0004)
> mine:doSomething(<ns:item><ns:subItem>text</ns:subItem></ns:it
> em>) -- invalid coercion: () as element()
>
> I've tried using an element constructor to create an element
> to pass to the function but I still get the same invalid
> coercion: () as element() error.
>
> Any ideas how I can get the abbreviated form to work?
>
> Thanks,
>
> Bob
>
>

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to