If you are still having issues, post the exact code you are using that shows 
the problem.


From: [email protected] 
[mailto:[email protected]] On Behalf Of Dave Liepmann
Sent: Tuesday, August 09, 2016 3:05 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] External variables as element() type

Got it. Thanks for your help, David.

On Mon, Aug 8, 2016 at 4:53 PM, David Lee 
<[email protected]<mailto:[email protected]>> wrote:
Once 'inside' the XQuery side, there is no ambiguity on types of values or 
variables.
You can use any of the following
xdmp:type() -- for Atomic types
xdmp:node-kind() for Node types
xdmp:describe() for any value

XQuery primitives   'instance of'  , 'typeswitch'
Test if values are a type or subtype with 'treat as'
Test if values can be converted to another type with 'cast as'

You can enforce the expected type by using 'as' in the variable declaration, eg.

declare variable $node as element() external ;




From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Dave Liepmann
Sent: Monday, August 08, 2016 10:24 AM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] External variables as element() type

Pursuant to this same question about sending Element variables, is there a way 
to verify from XQuery or MarkLogic that the variable I've created is in fact an 
Element and not a String? From the feedback above it's unclear if I can trust 
xdmp:type or getValueType.

Thanks,
Dave

On Sun, Jul 31, 2016 at 1:59 PM, Dave Liepmann 
<[email protected]<mailto:[email protected]>> wrote:
On Sat, Jul 30, 2016 at 3:35 PM, David Lee 
<[email protected]<mailto:[email protected]>> wrote:

You need to use ValueFactory.newElement to create Elements, it will not be done 
for you in this method.

Right, that was what I expected too! :) But when I pass a pre-created Element 
(such as the result of your above code) to setNewVariable, I get an 
IllegalArgumentException: "String, org.w3c.dom.Element or InputStream value 
required to construct element()". That message makes me suspect it is passing 
the buck to 
newElement<https://docs.marklogic.com/javadoc/xcc/com/marklogic/xcc/ValueFactory.html#newElement(java.lang.Object)>.

In contrast, setNewVariable accepts your `is` InputString variable, giving me 
the same results as when I passed a String, including the getValueType report 
that the variable is of type "element()". Using setVariable also gives me 
identical results in XQuery and getValueType.


_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to