expath to fetch a CSV file, as curl or wget

Skip to first unread message

Nicholas Saunders

Dec 28, 2020, 1:04:20 PM12/28/20
to EXPath

for a $url="example.com/foo.csv"

how is EXPath used to download the file?  Something like:

xquery version "3.1";

import module namespace hc = "http://expath.org/ns/http-client";

let $url := "http://www.bccdc.ca/Health-Info-Site/Documents/BCCDC_COVID19_Dashboard_Lab_Information.csv"

let $request :=
    <hc:request href="{$url}" method="GET">
        <hc:header name="Connection" value="close"/>    
    csv:parse($request, map { 'header': true() })

but I want parse the CSV to XML with something like:

let $text := file:read-text('addressbook.csv')
return csv:parse($text, map { 'header': true() })



Joe Wicentowski

Dec 28, 2020, 1:15:10 PM12/28/20
to exp...@googlegroups.com
Hi Nick,

Does fn:unparsed-text() not work for you for fetching the remote resource?

Are you using BaseX, which I gather from your use of the csv:parse() function? Depending on your implementation of the EXPath HTTP Client, the send-request() function may present text files to you in implementation-specific ways. This seems to be one area in which, for example, eXist and BaseX's implementations differ. Here's the BaseX code for retrieving the CSV file:

xquery version "3.1";

import module namespace http = "http://expath.org/ns/http-client";
    <http:request href="{$url}" method="GET">
        <http:header name="Connection" value="close"/>    
let $response := http:send-request($request)

This returns the CSV file as plain text. 

In eXist, you have to pass this $response[2] to util:binary-to-string() to achieve the same result.

However, both BaseX and eXist return identical plain text results when using fn:unparsed-text():



You received this message because you are subscribed to the Google Groups "EXPath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to expath+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/expath/8b3461a1-5815-4df5-8d2a-38bb70bdae45n%40googlegroups.com.
Reply all
Reply to author
0 new messages