Page 1 of 1

Fetch JSON from an API

Posted: Mon Mar 06, 2023 6:56 pm
by Oleksii
I need to get a JSON file from API like this http://dme-intern.mozarteum.local/digit ... -info/4087
As far it seems that the extension

Code: Select all

dp:url-open
would yield the needed result:
(cf. https://www.ibm.com/docs/en/datapower-g ... dpurl-open)

However, executing of this code

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<stylesheet exclude-result-prefixes="xs xd dme functx dp" version="3.0"
  xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp"
  xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:dme="http://www.mozarteum.at/ns/dme"
  xmlns:functx="http://www.functx.com" xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xpath-default-namespace="http://www.music-encoding.org/ns/mei">

  <template match="/">
    <result-document href="out.txt">
      <dp:url-open target="http://dme-intern.mozarteum.local/digital-editions/api/work-info/4087"
      > </dp:url-open>
    </result-document>
  </template>

</stylesheet>
triggers a Saxon error "Unknown extension instruction".
I suppose the extension should be declared somewhere. Am I correct? How to do it in oXygen (25.0, build 2023013006)?
P.S. I've searched in the Oxygen documentation for "Saxon extension" and also Saxon documentation like this section:
https://www.saxonica.com/html/documenta ... nsibility/
but did not find what I need.

Regards,
Oleksii

Re: Fetch JSON from an API

Posted: Tue Mar 07, 2023 8:43 am
by xephon
Hi,
I'm not familiar with this extension. What we do is to download the JSON with curl from Apache Ant first. Then we convert the JSON to XML and then we operate normally on the XML. This is surely the slowest solution, but very easy to maintain.
Best regards

Re: Fetch JSON from an API

Posted: Tue Mar 07, 2023 2:47 pm
by Oleksii
Thank you for the feedback!
Currently I suppose to go this path: https://stackoverflow.com/a/75661104/7315908