Author:
brentburgoyne
Version:
0.1
Released:
18 March 2010
Category:
Other

Closed#1: Error: Returning invalid XML

@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?

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.

This issue is closed.

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