Created
March 30, 2016 14:25
-
-
Save ableasdale/40e3daf53e56b646aacf0dd33b48e6b2 to your computer and use it in GitHub Desktop.
Getting a SPARQL ReST endpoint to return csv data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
declare variable $HOSTNAME := "yourhostname"; | |
declare variable $DATABASE := "Documents"; | |
declare variable $USERNAME := "user"; | |
declare variable $PASSWORD := "pass"; | |
declare variable $SPARQL-QUERY := 'SELECT DISTINCT * WHERE {?s ?p ?o} LIMIT 10'; | |
let $response := xdmp:http-post("http://"||$HOSTNAME||":8000/v1/graphs/sparql?database="||$DATABASE, | |
<options xmlns="xdmp:http"> | |
<headers> | |
<Content-type>{"application/x-www-form-urlencoded"}</Content-type> | |
<Accept>{"text/csv"}</Accept> | |
</headers> | |
<data>{'query='||$SPARQL-QUERY}</data> | |
<authentication method="digest"> | |
<username>{$USERNAME}</username> | |
<password>{$PASSWORD}</password> | |
</authentication> | |
</options>)[2] | |
return xdmp:save("/tmp/mycsv.csv", $response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment