Skip to content

Instantly share code, notes, and snippets.

@EdWarga
Created July 13, 2015 14:07
Show Gist options
  • Save EdWarga/f206d6bb9c41dc9957fa to your computer and use it in GitHub Desktop.
Save EdWarga/f206d6bb9c41dc9957fa to your computer and use it in GitHub Desktop.
XQ to harvest OAI-PMH records $verb=ListRecords
xquery version "3.0";
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";
declare namespace oai_dc = "http://www.openarchives.org/OAI/2.0/oai_dc/";
declare namespace qdc = "http://purl.org/dc/terms/";
declare function local:resume($base-url as xs:string, $token as xs:string) as document-node()
{
let $doc := fn:doc(($base-url || "?verb=ListRecords&resumptionToken=" || $token))
return
if ($doc//oai:resumptionToken = "") then ($doc, "LAST_RESPONSE.xml")
else (($doc, $doc//oai:resumptionToken/text()||".xml"), local:resume($base-url, $doc//oai:resumptionToken/text()))
};
let $base-url := "http://dash.harvard.edu/oai/request"
let $set-spec := "hdl_1_3345929"(:business stuff:)
let $request := fn:string-join(($base-url,"?verb=ListRecords&metadataPrefix=oai_dc&set=",$set-spec), '')
let $initial-response := doc($request)
return
local:resume($base-url, $initial-response//oai:resumptionToken/text())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment