Login   Register  
PHP Classes
elePHPant
Icontem

File: info.txt

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cristian Navalici  >  XML Currency Reader  >  info.txt  >  Download  
File: info.txt
Role: Documentation
Content type: text/plain
Description: Additional info
Class: XML Currency Reader
Retrieve currency exchange data from XML files
Author: By
Last change: Added information about how to extend the base class.
Date: 6 years ago
Size: 3,058 bytes
 

Contents

Class file image Download
==============================================
XML Currency Reader class
==============================================
This class implements support for xml currencies files, usually provided by central banks. It's a general class,
who must be extended with particulary classes (e.g. BNR_reader.class)

abstract class XML_currency
Variables:
    abstract protected function parse_rate_contents($content, $currency = 'EUR');
    abstract protected function parse_domdoc();

    protected $xmlpath
    protected $allow_url_fopen;
    protected $xml_content;
    protected $domdoc

Methods:
    public function __construct() 
    public function parse_xml() 
    protected function get_xml_content()
    protected function DOMconnector()


----------------------------------------
class BNR_reader extends XML_currency
Variables:
    inherited ones
    protected $xmlpathl => here the URL for xml file

Methods:
    inherited ones
    public function parse_rate_contents($content, $currency = 'EUR')
    public function parse_domdoc()


==============================================
USAGE FOR BNR READER CLASS:
==============================================
Usage is very simple, just call parse_xml method on a class object,
and then display on your page the needed value. More on index.php.


==============================================
XML FILE:
http://www.bnro.ro/nbrfxrates.xml
==============================================


==============================================
RETURNING ARRAY FORMAT:
==============================================

Array
(
    [0] => National Bank of Romania
    [1] => 2008-10-24
    [2] => Array
        (
            [0] => Array
                (
                    [currency] => AUD
                    [rate] => 1.8022
                    [multiplier] => 1
                )

            [1] => Array
                (
                    [currency] => BGN
                    [rate] => 1.8854
                    [multiplier] => 1
                )

...

            [19] => Array
                (
                    [currency] => XAU
                    [rate] => 65.5854
                    [multiplier] => 1
                )

            [20] => Array
                (
                    [currency] => XDR
                    [rate] => 4.2963
                    [multiplier] => 1
                )

        )
)

==============================================
HOW TO EXTEND THE XML_CURRENCY_READER CLASS
==============================================
This is very simple. Just create a class who extends the XML_Currency_reader.class
and add some content to $xmlpath (the xml file URL), and also two particulary methods:

parse_domdoc - who parse the xml content and returns it in your specified form (depends on the xml structure)
parse_rate_contents - (optional) method used to retrieve a currency from parsed content. You can also use
a direct array approach, but this methods makes it more intuitive.