Search

A new extension, “Dynamic JSON Datasource” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

@brentburgoyne - Did you get this working?

I followed your instructions verbatim, and I’m getting the following as my XML output.

<?xml version="1.0" encoding="utf-8" ?>
<data>
    <events />
    <open-library-api-detail valid="false">
        <error>XML returned is invalid.</error>
        <messages>
            <item>loadXML(): Start tag expected, '&lt;' not found in Entity, line: 1</item>
            <item>loadXML(): Start tag expected, '&lt;' not found in Entity, line: 1</item>
        </messages>
    </open-library-api-detail>
</data>

Here’s what my datasource file looks like…

<?php

    require_once(TOOLKIT . '/class.datasource.php');

    Class datasourceopen_library_api_detail extends Datasource{

        public $dsParamROOTELEMENT = 'open-library-api-detail';
        public $dsParamURL = 'http://openlibrary.org/api/books?bibkeys=ISBN:{$isbn}&callback=processOLBooks';
        public $dsParamXPATH = '/';
        public $dsParamCACHE = '30';
        public $dsParamTIMEOUT = '6';
        public function __construct(&$parent, $env=NULL, $process_params=true){
            parent::__construct($parent, $env, $process_params);
            $this->_dependencies = array();
        }

        public function about(){
            return array(
                     'name' => 'Open Library API Detail',
                     'author' => array(
                            'name' => 'Webmaster',
                            'website' => 'http://domain.com',
                            'email' => 'webmaster@domain.com'),
                     'version' => '1.0',
                     'release-date' => '2010-03-25T04:54:42+00:00');    
        }

        public function getSource(){
            return 'dynamic_xml';
        }

        public function allowEditorToParse(){
            return true;
        }

        public function grab(&$param_pool=NULL){
            $result = new XMLElement($this->dsParamROOTELEMENT);

            try{
                include(EXTENSIONS . '/dynamic_json/lib/datasource.dynamic_json.php');
            }
            catch(Exception $e){
                $result->appendChild(new XMLElement('error', $e->getMessage()));
                return $result;
            }   

            if($this->_force_empty_result) $result = $this->emptyXMLSet();
            return $result;
        }
    }

Any thoughts?

Unfortunately, I’m stuck. Anybody have any ideas on how to tackle this?

Sorry for being so slow to reply.

The issue with the source you are working with is that it is JSONP, not JSON. JSONP includes some extra information that breaks PHP’s json_decode() function. I made some changes to allow it to work with JSONP so you will want to grab the latest.

Let me know if you have any other issues.

Nice. That looks like it did the trick! Thank you sir!

This would be a great option to add under Custom XML under Blueprints > Data Sources.

So to be able to pick Static XML, Dynamic XML, Dynamic JSON/JSONP (which converts to XML) as this extension does.

That way you don’t have to edit the datasource manually, but can use the Symphony interface to do so.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details