PDA

Zobacz pełną wersję : XML Parsing Error at 1:30. Error 18: unknown encoding



kogutowski
26-05-2012, 21:46
Witam,

Na mojej Joomla 2.5 zainstalowalem moduł JExtCurrency z plugin do pobierania strumienia walut ze strony nbp.pl i tutaj zaczyna sie problem: wystwietla sie komunikat: "XML Parsing Error at 1:30. Error 18: unknown encoding"....a w miejscu modulu jedynie: "PLG_JEXTCURRENCY_ERROR_DATA". Korzystajac z tego modulu nie ma problemu z pobieraniem danych z innych bankow centralnych, problem pojawia sie jedynie przy NBP. Teoretycznie problem kojarzy mi sie z bledem kodowania, ale sprawdzalem kodowanie plikow i powinno sie zgadzac.

Czy ktos zechcialby doradzic??

Dziekuje z gory.

---------- Post dodany o 21:46 ---------- Poprzedni post był o 20:51 ----------

Dorzucam kod pliku, który nie działa:


<?php
/**
* @author stankiewiczpl.opole at gmail.com 12-Oct-2011
*/
// no direct access
defined('_JEXEC') or die('Restricted access');

/**
* Euro foreign exchange reference rates by the National Bank of Poland
*/
class currency_data_nbp extends currency_data
{
function __construct()
{
parent::__construct();
// $this->before_flag = FALSE; // differences b/w rates are taken from the same XML source
$this->url = "http://www.nbp.pl/kursy/xml/LastA.xml"; // last day rates
$this->bank_name = "Narodowy Bank Polski";
$this->bank_url = "http://www.nbp.pl/";
$this->currency_name = "PLN";
}

function get_array($xml, $day = '', $replace_currency_array)
{
// Handle no data received error
if (!isset ($xml->document->pozycja)) {
$error ['error'] = 1;
return $error;
}
// Save currencies' rates in an associative array indexed by currency 3 char code
$rates = array(); // array to store currencies exchange rates
$data = $xml->document->pozycja;
$rates ['date'] = $xml->document->data_publikacji [0]->data();
foreach ($data as $dt) {
$code = $dt->kod_waluty [0]->data();
// Store data for selected by user currencies only, if they are set
if (empty ($this->currencies) || in_array($code, $this->currencies)) {
$rates ['currency'] [$code] ['scale'] = $dt->przelicznik [0]->data(); // units
$rates ['currency'] [$code] ['name'] = parent::replace_currency_name($dt->nazwa_waluty [0]->data(), $code, $replace_currency_array);
$rates ['currency'] [$code] ['rate'] = str_replace(',', '.', $dt->kurs_sredni [0]->data());
}
}
// Save additional info (only one time)
if ($day == 'today' || $this->before_flag == FALSE) {
$rates['info'] = array(
"bank_name" => $this->bank_name,
"bank_url" => $this->bank_url,
"currency_name" => $this->currency_name);
}
return $rates;
}


public function getUrl($date = "")
{
if (strlen($date) > 1) {
$file = file_get_contents('http://nbp.pl/Kursy/xml/dir.txt'); //list filenames of last days rates
preg_match_all('/^(a.+)/mi', $file, $pregs);
$count = count($pregs[1]) - 2;
$filename = $pregs[1][$count];
$xml_source = substr($filename, 0, -1);
$url = 'http://nbp.pl/Kursy/xml/' . $xml_source . '.xml'; //before last day rates
} else {
$url = $this->url;
}
return $url;
}

}

Dorzucam kod pliku działającego:

<?php

/**

* @author Gray <justPHP@gmail.com>

* @date 9-Oct-2010

* @copyright (c)2010 justPHP.net

*/



// no direct access

defined('_JEXEC') or die('Restricted access');





/**

* Euro foreign exchange reference rates by the European Central Bank

*/

class currency_data_ecb extends currency_data {



function __construct() {

parent::__construct();

$this->before_flag = FALSE; // differences b/w rates are taken from the same XML source

$this->url = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"; // last 90 days rates

$this->bank_name = "European Cenral Bank";

$this->bank_url = "http://www.ecb.int/";

$this->currency_name = "Euro";

}





function get_array($xml, $day = '', $replace_currency_array) {



// Handle no data received error

if (!isset($xml->document->Cube[0])&&!isset($xml->document->Cube[1])) {

$error['error'] = 1;

return $error;

}



// Save currencies' rates in an associative array indexed by currency 3 char code

$rates = array(); // array to store currencies exchange rates

$rates['date'] = $xml->document->Cube[0]->_attributes['time']; // date

$data = $xml->document->Cube[0]->_children;

$data2 = $xml->document->Cube[1]->_children; // previouse day's rates



for($i = 0; $i < count ($data); $i ++) {

$code = $data[$i]->_attributes['currency'];

// Store data for selected by user currencies only, if they are set

if (empty($this->currencies) || in_array($code, $this->currencies)) {

$rates['currency'][$code]['scale'] = 1; // units; not present in this XML

// Set currency name (array with replacement rules will be searched for the ISO code)

$rates['currency'][$code]['name'] = parent::replace_currency_name($code, $code, $replace_currency_array);

$rates['currency'][$code]['rate'] = $data[$i]->_attributes['rate']; // rate

// Calculate and store change to previsous day; preg_replace() is for avoiding bulk format in serialized array

$change = $data[$i]->_attributes['rate'] - $data2[$i]->_attributes['rate'];

$change = preg_replace('/d:([0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)?);/e', "'d:'.((float)$1).';'", $change);

$rates['currency'][$code]['change'] = $change;

}

}



// Save additional info (only one time)

if ($day == 'today' || $this->before_flag == FALSE) {

$rates['info'] = array(

"bank_name" => $this->bank_name,

"bank_url" => $this->bank_url,

"currency_name" => $this->currency_name);

}



return $rates;

}

}