The Request.setNewVariable<https://docs.marklogic.com/javadoc/xcc/com/marklogic/xcc/Request.html#setNewVariable(java.lang.String,%20com.marklogic.xcc.types.ValueType,%20java.lang.Object)> is a low level API. Most types have convenience wrapper API's that are type safe. This api is to cover the remaining cases or for general purpose code to avoid having a big switch table all over, in exchange it makes you responsible for passing the correct value type corresponding the type indicated.
To support many types, the argument values are 'Object' and are not validated It does not *convert* the value to the specified type, rather it *assumes* you have given it the correct type. In your case your passing a string but saying its an element. I don’t know and can't easily predict in what ways it will misbehave -- just "don’t do that" ... You need to use ValueFactory.newElement to create Elements, it will not be done for you in this method. From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Dave Liepmann Sent: Saturday, July 30, 2016 5:05 AM To: MarkLogic Developer Discussion <general@developer.marklogic.com> Subject: Re: [MarkLogic Dev General] External variables as element() type Hi David, thanks for lending a hand! I apologize for hiding this fact in my initial inquiry, but I'm using Request.setNewVariable<https://docs.marklogic.com/javadoc/xcc/com/marklogic/xcc/Request.html#setNewVariable(java.lang.String,%20com.marklogic.xcc.types.ValueType,%20java.lang.Object)>("foo", ValueType.ELEMENT, "<foo/>") to create the variable. Should I expect this to send a string or an element()? If before making the Request I call getVariables and interrogate getValueType I am told the new variable is indeed "element()". Is this response trustworthy? Thanks, Dave On Sat, Jul 30, 2016 at 1:47 AM, David Lee <david....@marklogic.com<mailto:david....@marklogic.com>> wrote: Your still sending a 'string' Use this instead. String xmlString = "<element><child/></element>" InputStream is = new ByteArrayInputStream( xmlString.toBytes("UTF-8")); com.marklogic.xcc.types.XdmValue value = ValueFactory.newElement(is); From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>] On Behalf Of Dave Liepmann Sent: Friday, July 29, 2016 7:20 AM To: general@developer.marklogic.com<mailto:general@developer.marklogic.com> Subject: [MarkLogic Dev General] External variables as element() type Hi MarkLogic folks! I'd like to pass an XML element as an external variable to my query using MarkLogic XCC/J and have it be recognized as type element() when it arrives in XQuery. I set my-variable to "<foo/>" (or "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo></foo>", no difference) using setNewVariable on the Request, with "element()" for the ValueType. Then: xquery version \"1.0-ml\"; declare variable $my-variable as element() external; xdmp:type(xdmp:unquote($my-variable)) This returns "untypedAtomic". Is this expected behavior? I'd like to see it come through typed as an element(). Is there a better way, either in XQuery or in the Request, to set the type of an external variable? Thanks in advance, Dave Liepmann _______________________________________________ General mailing list General@developer.marklogic.com<mailto:General@developer.marklogic.com> Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general