[xquery-talk] Recursion or not - how to (re)query an API

Bridger Dyson-Smith bdysonsmith at gmail.com
Mon Jan 18 08:58:35 PST 2016


Hi Christian,

thank you for your help. I'm using BaseX 8.3.1 as my query processor. I'm
guilty, I'm afraid, of presenting a poorly framed question to the list. I
need to mull over the problem a little more.

Thanks again!
Bridger

On Mon, Jan 18, 2016 at 11:32 AM, Christian Grün <christian.gruen at gmail.com>
wrote:

> Hi Bridger,
>
> I know too little about the API you are working, and your query
> processor (parts of the semantics of fn:doc are
> implementation-defined), but I noticed that the URL construction might
> need to be revised:
>
> OLD:
>   local:getPID(doc("$in" || "&sessionToken=" || "$rQ"))
>
> NEW:
>   local:getPID(doc($in || "&sessionToken=" || encode-for-uri($rQ)))
>
> Possibly, $in (or a part of it) needs to be encoded as well.
>
> Hope this helps,
> Christian
>
>
>
> On Mon, Jan 18, 2016 at 5:09 PM, Bridger Dyson-Smith
> <bdysonsmith at gmail.com> wrote:
> > Hi all,
> >
> > I'm struggling with getting a working example of the following problem:
> I'm
> > sending a query to an API that returns some data and, if the data set is
> > large enough, a resumption token to requery the API.
> >
> > I'm stuck at the point of how to generate the new query URL, while still
> > processing the new data. Is the best idea to create a function that will
> > update a new request to the API, or is there a different approach that
> can
> > be used?
> >
> > I've made several attempts with functions -- the latest non-working
> examples
> > are below -- and I'm missing... something, but I don't know what.
> >
> > Thanks for any guidance you can provide.
> > Cheers,
> > Bridger
> >
> > (: sample query :)
> > (:
> >
> http://server:8080/fedora/objects?query=pid~{$collection}*&resultFormat=xml&pid=true
> > :)
> >
> > declare variable $query external :=
> > '
> http://our.server:8080/fedora/objects?query=pid~gamble*&resultFormat=xml&pid=true
> ';
> > declare variable $sessionToken := '&sessionToken=';
> > declare variable $resToken := '';
> >
> > (:functions:)
> > (:doesn't work:)
> > declare function local:getPID($in as document-node()) as
> xs:anyAtomicType*
> > {
> >   data($in/*:resultList/*:objectFields/*:pid)
> > };
> >
> > (:doesn't work:)
> > declare function local:reQuery(
> >   $in as document-node(),
> >   $rQ as xs:untypedAtomic*) as document-node()
> > {
> >   let $rQ := $in/*:listSession/*:token/text()
> >   return (
> >     if ($rQ) then
> >       local:getPID(doc("$in" || "&sessionToken=" || "$rQ"))
> >     else ()
> >   )
> > };
> >
> > (: this works processing the descendant elements but doesn't recurse :)
> > for $result in fn:doc($query)/*:result
> > let $resToken := $result/*:listSession/*:token/text()
> > let $pid := $result/*:resultList/*:objectFields/*:pid/text()
> > return (
> >   $result,
> >   $resToken,
> >   $pid
> > )
> >
> > (: sample returned from query; e.g. $result :)
> > <result xmlns="http://www.fedora.info/definitions/1/0/types/"
> > xmlns:types="http://www.fedora.info/definitions/1/0/types/"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="http://www.fedora.info/definitions/1/0/types/
> > http://localhost:8080/fedora/schema/findObjects.xsd">
> >   <listSession>
> >     <token>63c0762b5eb3d4b46c58add843b7b3e6</token>
> >     <cursor>0</cursor>
> >     <expirationDate>2016-01-18T01:40:05.381Z</expirationDate>
> >   </listSession>
> >   <resultList>
> >     <objectFields>
> >       <pid>gamble:1</pid>
> >     </objectFields>
> >     <objectFields>
> >       <pid>gamble:10</pid>
> >     </objectFields>
> >   </resultList>
> > </result>
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > talk at x-query.com
> > http://x-query.com/mailman/listinfo/talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20160118/179504f1/attachment.html>


More information about the talk mailing list