expath to fetch a CSV file, as curl or wget

2 views
Skip to first unread message

Nicholas Saunders

unread,
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"/>    
    </hc:request>
return
    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() })




thanks,

Nick

Joe Wicentowski

unread,
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"/>    
    </http:request>
let $response := http:send-request($request)
return
    $response[2]
```

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():

```
```

Joe

--
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
Forward
0 new messages