Re: [MarkLogic Dev General] External variables as element() type

2016-08-11 Thread Dave Liepmann
On Tue, Aug 9, 2016 at 1:30 PM, David Lee  wrote:

> If you are still having issues, post the exact code you are using that
> shows the problem.
>
>
I would have earlier, except I am working from Clojure and have not done
the legwork to duplicate my results directly in Java, and would prefer not
to bring a layer of language obfuscation into the matter. I believe
xdmp:node-kind() verifies my original suspicion (better than xdmp:type()),
which is that my variables are coming through as elements.
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] External variables as element() type

2016-08-09 Thread David Lee
If you are still having issues, post the exact code you are using that shows 
the problem.


From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Dave Liepmann
Sent: Tuesday, August 09, 2016 3:05 AM
To: MarkLogic Developer Discussion 
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 
mailto:david@marklogic.com>> 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: 
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: Monday, August 08, 2016 10:24 AM
To: MarkLogic Developer Discussion 
mailto:general@developer.marklogic.com>>
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 
mailto:dave.liepm...@gmail.com>> wrote:
On Sat, Jul 30, 2016 at 3:35 PM, David Lee 
mailto:david@marklogic.com>> 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
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


Re: [MarkLogic Dev General] External variables as element() type

2016-08-09 Thread Dave Liepmann
Got it. Thanks for your help, David.

On Mon, Aug 8, 2016 at 4:53 PM, David Lee  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:* general-boun...@developer.marklogic.com [mailto:general-bounces@
> developer.marklogic.com] *On Behalf Of *Dave Liepmann
> *Sent:* Monday, August 08, 2016 10:24 AM
> *To:* MarkLogic Developer Discussion 
> *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 
> wrote:
>
> On Sat, Jul 30, 2016 at 3:35 PM, David Lee 
> 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
> 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


Re: [MarkLogic Dev General] External variables as element() type

2016-08-08 Thread David Lee
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: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Dave Liepmann
Sent: Monday, August 08, 2016 10:24 AM
To: MarkLogic Developer Discussion 
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 
mailto:dave.liepm...@gmail.com>> wrote:
On Sat, Jul 30, 2016 at 3:35 PM, David Lee 
mailto:david@marklogic.com>> 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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] External variables as element() type

2016-08-08 Thread Dave Liepmann
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 
wrote:

> On Sat, Jul 30, 2016 at 3:35 PM, David Lee 
> 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
> 
> .
>
> 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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] External variables as element() type

2016-07-31 Thread Dave Liepmann
On Sat, Jul 30, 2016 at 3:35 PM, David Lee  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

.

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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] External variables as element() type

2016-07-30 Thread David Lee
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 
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, "") 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 
mailto:david@marklogic.com>> wrote:
Your still sending a 'string'
Use this instead.

   String xmlString = ""
   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 "" (or "", 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


Re: [MarkLogic Dev General] External variables as element() type

2016-07-30 Thread Dave Liepmann
Hi David, thanks for lending a hand!

I apologize for hiding this fact in my initial inquiry, but I'm using
Request.setNewVariable
("foo",
ValueType.ELEMENT,
"") 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  wrote:

> Your still sending a 'string'
>
> Use this instead.
>
>
>
>String xmlString = ""
>
>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] *On Behalf Of *Dave Liepmann
> *Sent:* Friday, July 29, 2016 7:20 AM
> *To:* 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 "" (or " encoding=\"UTF-8\"?>", 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
> 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


Re: [MarkLogic Dev General] External variables as element() type

2016-07-29 Thread David Lee
Your still sending a 'string'
Use this instead.

   String xmlString = ""
   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] On Behalf Of Dave Liepmann
Sent: Friday, July 29, 2016 7:20 AM
To: 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 "" (or "", 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
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general