Or if you can't change the inner quotes (depending on the source of your XML), then replace the outer quotes with the xdmp:quote function:
xquery version "1.0-ml"; declare namespace ns= "http://urn:my:namespace"; let $item := xdmp:unquote(xdmp:quote(<ns:item xmlns:ns="http://urn:my:namespace"><ns:subItem>text</ns:subItem></ns:item>)) /ns:item return $item _____ From: [email protected] [mailto:[email protected]] On Behalf Of Tim Meagher Sent: Thursday, April 23, 2009 3:45 PM To: 'General Mark Logic Developer Discussion' Subject: RE: [MarkLogic Dev General] Coercion error passing element to function Hi Robert, Two things: 1. Declare the namespace for ns 2. Use single instead of double quotes within the xml string For example: xquery version "1.0-ml"; declare namespace ns= "http://urn:my:namespace"; let $item := xdmp:unquote("<ns:item xmlns:ns='http://urn:my:namespace'><ns:subItem>text</ns:subItem></ns:item>") /ns:item return $item Tim Meagher _____ From: [email protected] [mailto:[email protected]] On Behalf Of Runstein, Robert E. (Contr) (IS) Sent: Thursday, April 23, 2009 3:24 PM 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:subItem></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:item>) -- 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
