http:request parsing question
Wednesday, 23 October 2019 · 6 messages · last reply 29 Oct 2019
BD
Bridger Dyson-Smith23 Oct 2019 03:30 #
Hi all -
I was hoping that someone on the list could help with my thinking about parsing the http:response values from a request; I've tried the following, but I'm not thinking about this correctly.
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";
declare namespace h = "http://expath.org/ns/http-client";
http:send-request(<http:request method='get' href='
http://export.arxiv.org/oai2?verb=Identify'/>)//@status/data()returns '200', but trying
http:send-request(<http:request method='get' href='
http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status
fails.
I'm guessing (but am not sure) that the combination of the <http:response> with the body of the response is causing my problem, but I'm not sure how to wiggle my way around it.
Note: this is not in a RESTXQ context (yet), but for my simple trials is there a way to get at the http -namespace elements?
Thank you for your time and trouble.
Best,
BridgerLQ
Liam R. E. Quin23 Oct 2019 03:38 #
Quoted text · Bridger Dyson-Smith · 10 lines
On Tue, 2019-10-22 at 19:32 -0400, Bridger Dyson-Smith wrote: > > http://export.arxiv.org/oai2?verb=Identify'/>)//@status/data() > > returns '200', but trying > > http:send-request(<http:request method='get' href=' > http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status > > fails.
I'm guessing that the first request sends you an auth token, and that you're supposed to send this as a parameter in the second token?
How exactly does the second call fail?
--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
BD
Bridger Dyson-Smith23 Oct 2019 07:11 #
Hi Liam!
Quoted text · Liam R. E. Quin · 19 lines
On Tue, Oct 22, 2019 at 7:38 PM Liam R. E. Quin <liam at fromoldbooks.org> wrote: > On Tue, 2019-10-22 at 19:32 -0400, Bridger Dyson-Smith wrote: > > > > http://export.arxiv.org/oai2?verb=Identify'/>)//@status/data() > > > > returns '200', but trying > > > > http:send-request(<http:request method='get' href=' > > http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status > > > > fails. > > I'm guessing that the first request sends you an auth token, and that > you're supposed to send this as a parameter in the second token? > > How exactly does the second call fail? > > Apologies for not clarifying. The @href points to an OAI-PMH endpoint,
which simply returns a XML response[1] saying, "This is an OAI-PMH endpoint, here's an administrator's email address, plus some other stuff." So, there aren't any tokens being passed back in forth in this case (to be honest, there are resumption tokens that can be passed back in to an OAI provider for other types of requests).
I had thought it might be a good idea to try to think about the HTTP status ('200', '404', etc) in a thing I'm working on, and while I realize I can get to it with a
//@status , I had thought a more direct expression would be more suited (what if there are other @status attributes, etc). I even tried taking my shoes off, to no avail. :)
In any case, thank you!
Best,
BridgerQuoted text · Liam R. E. Quin · 7 lines
> -- > Liam Quin, https://www.delightfulcomputing.com/ > Available for XML/Document/Information Architecture/XSLT/ > XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. > Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org > > [1] The full response from arXiv's OAI endpoint looks like this:
<?xml version="1.0" encoding="UTF-8"?><OAI-PMH
xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"><responseDate>2019-10-22T23:18:26Z</responseDate><request
verb="Identify">http://export.arxiv.org/oai2</request><Identify><repositoryName>arXiv</repositoryName><baseURL>http://export.arxiv.org/oai2</baseURL><protocolVersion>2.0</protocolVersion><adminEmail>help at arxiv.org</adminEmail><earliestDatestamp>2007-05-23</earliestDatestamp><deletedRecord>persistent</deletedRecord><granularity>YYYY-MM-DD</granularity><description><eprints
xmlns="http://www.openarchives.org/OAI/1.1/eprints"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/1.1/eprints
http://www.openarchives.org/OAI/1.1/eprints.xsd"> <content>
<text>Author self-archived e-prints</text> </content> <metadataPolicy>
<text>Metadata harvesting permitted through OAI interface</text>
<URL>http://arxiv.org/help/oa/metadataPolicy</URL> </metadataPolicy>
<dataPolicy> <text>Full-content harvesting not permitted (except by
special arrangement)</text>
<URL>http://arxiv.org/help/oa/dataPolicy</URL> </dataPolicy>
<submissionPolicy> <text>Author self-submission preferred,
submissions screened for appropriateness.</text>
<URL>http://arxiv.org/help/submit</URL>
</submissionPolicy></eprints></description><description><branding
xmlns="http://www.openarchives.org/OAI/2.0/branding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/branding/
http://www.openarchives.org/OAI/2.0/branding.xsd"> <collectionIcon>
<url>http://arxiv.org/OAI/arXivLogo.png</url>
<link>http://arxiv.org/</link> <title>arXiv e-print archive</title>
<width>88</width> <height>31</height>
</collectionIcon><metadataRendering
metadataNamespace="http://www.openarchives.org/OAI/2.0/oai_dc/"
mimeType="text/xsl">http://arxiv.org/OAI/arXivMetadata.xsl</metadataRendering></branding></description></Identify></OAI-PMH>BD
Bridger Dyson-Smith27 Oct 2019 03:24 #
Hi all -
Quoted text · Bridger Dyson-Smith · 41 lines
On Tue, Oct 22, 2019 at 11:13 PM Bridger Dyson-Smith <bdysonsmith at gmail.com> wrote: > Hi Liam! > > On Tue, Oct 22, 2019 at 7:38 PM Liam R. E. Quin <liam at fromoldbooks.org> > wrote: > >> On Tue, 2019-10-22 at 19:32 -0400, Bridger Dyson-Smith wrote: >> > >> > http://export.arxiv.org/oai2?verb=Identify'/>)//@status/data() >> > >> > returns '200', but trying >> > >> > http:send-request(<http:request method='get' href=' >> > http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status >> > >> > fails. >> >> I'm guessing that the first request sends you an auth token, and that >> you're supposed to send this as a parameter in the second token? >> >> How exactly does the second call fail? >> >> Apologies for not clarifying. The @href points to an OAI-PMH endpoint, > which simply returns a XML response[1] saying, "This is an OAI-PMH > endpoint, here's an administrator's email address, plus some other stuff." > So, there aren't any tokens being passed back in forth in this case (to be > honest, there are resumption tokens that can be passed back in to an OAI > provider for other types of requests). > > I had thought it might be a good idea to try to think about the HTTP > status ('200', '404', etc) in a thing I'm working on, and while I realize I > can get to it with a `//@status` , I had thought a more direct expression > would be more suited (what if there are other `@status` attributes, etc). I > even tried taking my shoes off, to no avail. :) > > In any case, thank you! > Best, > Bridger > > After thinking about this some more, I realized that wrapping the overall
HTTP response in my own element let's me write the sorts of expressions I
was thinking about. E.g.
declare namespace http = "http://expath.org/ns/http-client";
let $r :=
<resp>
{ http:send-request(<http:request method='get'/>, '
http://export.arxiv.org/oai2?verb=Identify') }
</resp>
return $r/http:response/@status/data()I'm curious, though, what other people are doing in the context of their RESTXQ applications? Are you wrapping responses in elements, or processing them some other way (I looked through the Web Module[2] documentation but didn't see anything that looked apropos.
In any case, enjoy your weekend.
Best,
Bridger
Quoted text · Bridger Dyson-Smith · 13 lines
>> -- >> Liam Quin, https://www.delightfulcomputing.com/ >> Available for XML/Document/Information Architecture/XSLT/ >> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. >> Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org >> >> [1] The full response from arXiv's OAI endpoint looks like this: > ``` > > <?xml version="1.0" encoding="UTF-8"?><OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"><responseDate>2019-10-22T23:18:26Z</responseDate><request verb="Identify">http://export.arxiv.org/oai2</request><Identify><repositoryName>arXiv</repositoryName><baseURL>http://export.arxiv.org/oai2</baseURL><protocolVersion>2.0</protocolVersion><adminEmail>help at arxiv.org</adminEmail><earliestDatestamp>2007-05-23</earliestDatestamp><deletedRecord>persistent</deletedRecord><granularity>YYYY-MM-DD</granularity><description><eprints xmlns="http://www.openarchives.org/OAI/1.1/eprints" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/1.1/eprints http://www.openarchives.org/OAI/1.1/eprints.xsd"> <content> <text>Author self-archived e-prints</text> </content> <metadataPolicy> <text>Metadata harvesting permitted through OAI interface</text> <URL>http://arxiv.org/help/oa/metadataPolicy</URL> </metadataPolicy> <dataPolicy> <text>Full-content harvesting not permitted (except by special arrangement)</text> <URL>http://arxiv.org/help/oa/dataPolicy</URL> </dataPolicy> <submissionPolicy> <text>Author self-submission preferred, submissions screened for appropriateness.</text> <URL>http://arxiv.org/help/submit</URL> </submissionPolicy></eprints></description><description><branding xmlns="http://www.openarchives.org/OAI/2.0/branding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/branding/ http://www.openarchives.org/OAI/2.0/branding.xsd"> <collectionIcon> <url>http://arxiv.org/OAI/arXivLogo.png</url> <link>http://arxiv.org/</link> <title>arXiv e-print archive</title> <width>88</width> <height>31</height> </collectionIcon><metadataRendering metadataNamespace="http://www.openarchives.org/OAI/2.0/oai_dc/" mimeType="text/xsl">http://arxiv.org/OAI/arXivMetadata.xsl</metadataRendering></branding></description></Identify></OAI-PMH> > > ``` >
CG
Hi Bridger,
Quoted text · Bridger Dyson-Smith · 2 lines
> http:send-request(<http:request method='get' href='http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status > fails.
The reason is that
http:send-request returns an http:response element as first item. "/h:response" is just another writing for
"/child::h:response", As the response has no other response child, you won’t get any result. This is what you can do instead:
1. Use the self axis: let $data := http:send-request(<http:request method='get'
href='http://export.arxiv.org/oai2?verb=Identify'/>)
return $data/self::http:response/@status2. Return the status attribute from the first result (which will always be the http:response element):
let $data := http:send-request(<http:request method='get'
href='http://export.arxiv.org/oai2?verb=Identify'/>)
return head($data)/@statusHope this helps,
Christian
BD
Bridger Dyson-Smith29 Oct 2019 20:06 #
Hi Christian,
as usual, you're very helpful!
One more example of how it can really help to pay attention to those function signatures -- I wasn't thinking about the http:response as a sequence, so thank you very much for that insight!
Best,
Bridger
Quoted text · Christian Grün · 29 lines
On Mon, Oct 28, 2019 at 10:13 PM Christian Grün <christian.gruen at gmail.com> wrote: > Hi Bridger, > > > http:send-request(<http:request method='get' href=' > http://export.arxiv.org/oai2?verb=Identify'/>)/h:response/@status > > fails. > > The reason is that http:send-request returns an http:response element > as first item. "/h:response" is just another writing for > "/child::h:response", As the response has no other response child, you > won’t get any result. This is what you can do instead: > > 1. Use the self axis: > > let $data := http:send-request(<http:request method='get' > href='http://export.arxiv.org/oai2?verb=Identify'/>) > return $data/self::http:response/@status > > 2. Return the status attribute from the first result (which will > always be the http:response element): > > let $data := http:send-request(<http:request method='get' > href='http://export.arxiv.org/oai2?verb=Identify'/>) > return head($data)/@status > > Hope this helps, > Christian >
Written for BaseX 9.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery