Thanks, David.

Your <res> trick helped.  Apparently what I have is a JSON object.  So I am
able to use json:transform-from-json on it, and then asW3cDocument() on the
result Item.

marc



On Thu, Jun 12, 2014 at 1:11 PM, David Ennis <[email protected]> wrote:

> HI.
>
> Whatever you are trying to return at this point is not a type that can be
> understood (like node or map).
>
> Before returning it, you need to transform or serialize it.
>
> The quickest and dirtiest way to start to see what is going on is to
> serialize it.
>
> Assume you have $var
>
> return $var
>
> Change that to
> return <res>{$var}</res>
>
> Wrapping it in an XML element causes MarkLogic to serialize complex
> objects.  Then you can look and see what is being returned.
>
> We usually pack things into map:map and transform this to json for
> transport.
>
> Kind Regards,
> David
>
>
> On 12 June 2014 18:45, Marc Limotte <[email protected]> wrote:
>
>> I'm trying this solution out now.  It seems to run the query, but then I
>> get this exception:
>>
>> Caused by: java.io.IOException: Nodes of type 'object' are not supported
>> in XCC result sequences
>>
>> at
>> com.marklogic.xcc.impl.AbstractResultSequence.nodeFactory(AbstractResultSequence.java:237)
>>
>> at
>> com.marklogic.xcc.impl.AbstractResultSequence.instantiateResultItem(AbstractResultSequence.java:191)
>>
>> at
>> com.marklogic.xcc.impl.CachedResultSequence.<init>(CachedResultSequence.java:56)
>>
>> at
>> com.marklogic.xcc.impl.handlers.GoodQueryResponseHandler.handleResponse(GoodQueryResponseHandler.java:48)
>>
>> at
>> com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(EvalRequestController.java:83)
>>
>> at
>> com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(AbstractRequestController.java:86)
>>
>> ...
>>
>>
>> What does this mean and any suggestions on how to fix it?
>>
>>
>> thanks,
>>
>> marc
>>
>>
>>
>>
>> On Thu, Jun 5, 2014 at 1:49 PM, Michael Blakeley <[email protected]>
>> wrote:
>>
>>> You could call https://docs.marklogic.com/sem:sparql through an XCC
>>> moduleInvoke, something like this:
>>>
>>> xquery version "1.0-ml";
>>> (: sparql.xqy :)
>>> import module namespace sem="http://marklogic.com/semantics";
>>>   at "/MarkLogic/semantics.xqy" ;
>>> (: Add more variables to support bindings, etc. as needed :)
>>> declare variable $SPARQL as xs:string external ;
>>> sem:sparql($SPARQL)
>>> (: end :)
>>>
>>> Then in Java:
>>>
>>> Session session = contentSource.newSession("mydatabase");
>>> Request request = session.newModuleInvoke("sparql.xqy");
>>> request.setNewStringVariable('SPARQL', mySparqlQuery);
>>> // add more variables to support bindings, etc. as needed.
>>> ResultSequence rs = session.submitRequest(request);
>>> while (rs.hasNext()) {
>>>     ResultItem item = rs.next();
>>>     // handle the item
>>> }
>>> session.close();
>>>
>>> Wrap that up in a utility class, parameterize it as needed, and you'll
>>> never have to think about it again.
>>>
>>> -- Mike
>>>
>>> On 5 Jun 2014, at 09:43 , Marc Limotte <[email protected]> wrote:
>>>
>>> > Hi.
>>> >
>>> > I'd like to run a SPARQL query from Java.  I've found various bits of
>>> documentation (including
>>> http://developer.marklogic.com/learn/semantics-exercises/sparql-101).
>>>  But the docs all seem to cover running SPARQL from the console or maybe
>>> REST or Xquery.  Can someone point me in the right direction for running a
>>> SPARQL query in Java?
>>> >
>>> > I don't need detailed instructions, just an overview or a pointer to
>>> the right documentation.
>>> >
>>> > thanks for any help,
>>> > Marc
>>> >
>>> > _______________________________________________
>>> > General mailing list
>>> > [email protected]
>>> > http://developer.marklogic.com/mailman/listinfo/general
>>>
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://developer.marklogic.com/mailman/listinfo/general
>>>
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to