Hi Andreas,
I was surprised indeeed to see entities escaped in the original response. In the Reddit documentation, I found this:
response body encoding For legacy reasons, all JSON response bodies currently have <, >, and & replaced with <, >, and &, respectively. If you wish to opt out of this behaviour, add a raw_json=1 parameter to your request.
You could try two things:
1. specify "...?raw_json=1" in your URL, 2. unescape the three entities in a subsequent step:
let $data := <body__html>&lt;div class="md"&gt;&lt;p&gt;Really cool. Wish I had your talent!&lt;/p&gt; &lt;/div&gt;</body__html> let $unescaped := $data => replace(``[<]``, ``[<]``) => replace(``[>]``, ``[>]``) => replace(``[&]``, ``[&]``) let $xml := parse-xml($unescaped) return $xml
Hope this helps, Christian
On Mon, Aug 17, 2020 at 9:07 PM Andreas Mixich mixich.andreas@gmail.com wrote:
Am 17.08.2020 um 09:25 schrieb Christian Grün:
Hi Andreas,
Before we fix the outcome, we should have a look at the initial HTTP response. I assume the following function invokes http:send-request?
1. let $data := local:get-article($token, concat($local:ahost,
$link))/json
True. It's just a simple wrapper around `http:send-request#1`, that takes care of setting up the `http:request/` element and issues it, returning the `http:response/`:
declare function local:get-article( $token as element(json), $link as xs:string) { let $request := <http:request href="{$link}" method="get"> <http:header name="Authorization"
value="{$token/token__type/data() || ' ' ||$token/access__token/data()}"/> <http:header name="User-Agent" value="{$local:user-agent}"/> </http:request> return http:send-request($request) };
Could you supply us with the full HTTP response (header and body)?
Sure. I am going to send it privately to you, since the cookie data may contain secrets. Note, that the data in question can be found in a JSON-key named `body_html`.
Do you have the REST API under control?
No. It is the Reddit API, documented here[1]. I use it according to [2].
-- Goody Bye, Minden jót, Mit freundlichen Grüßen, Andreas Mixich