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

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


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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20160118/b6d0ecc5/attachment.html>


More information about the talk mailing list