I’ll add also the xml2json formatter with a more complex xml response in case it’s eventually needed.
XML response:
https://www.w3schools.com/xml/plant_catalog.xml
PHP SC formatter:
<?php
namespace lib\core;
function formatter_xml2json($val) {
$xml = simplexml_load_string(strval($val));
return json_decode(json_encode($xml));
}
SC file
<?php
require('../../dmxConnectLib/dmxConnect.php');
$app = new \lib\App();
$app->define(<<<'JSON'
{
"settings": {
"options": {}
},
"meta": {
"options": {}
},
"exec": {
"steps": [
{
"name": "api1",
"module": "api",
"action": "send",
"options": {
"url": "https://www.w3schools.com/xml/plant_catalog.xml",
"dataType": "text"
},
"output": false
},
{
"name": "json",
"module": "core",
"action": "setvalue",
"options": {
"value": "{{api1.data.xml2json()}}"
},
"output": true
}
]
}
}
JSON
);
?>
Output