__call()
__construct()
__get()
__set()
autoConvert()
convert()
convertString()
formatDate()
image()
mapConvert()
setParams()
_setParam()
$channel
$delimiter
$enclosure
$filename
$header
$importFrom
$importTo
$item
$map
$output
$selectedFields
$url
$xml
class Xml2Csv
@author Axel Roszkopf, WEBAX, 2013
version | 1.0, 15.3.2013 This class is an easy to use, highly customisable XML to CSV converter. You can automatically convert XML to CSV, with only 1 parameter - the XML input (file or string). Advanved features include custom selection of the output fields, setting CSV delimiter and enclosure character etc. Features: - easy conversion with only 1 parameter through static function call - file or string as XML input - CSV delimiter and enclosure character setting - custom mapping of XML nodes to CSV fields - custom export field selection - setting parameters easily by chained function calls or by accessing them directly - possibilty to mass-setup of paramters - set an interval to limit the number of processed items (from, to) Examples: <code> // Example 1 - easy automatic conversion XmlToCsv::convert('example.xml'); // Example 2 - chained parameter setting $x = new XmlToCsv(); echo $x->url('example.xml') ->output(false) ->autoConvert(); // Example 3 - parameters set separately by directly accessing the class variables $x = new XmlToCsv(); $x->url = 'example.xml'; $x->output = false; echo $x->autoConvert(); // Example 4 - parameters set at object creation as an array $x = new XmlToCsv(array( 'url'=>'example.xml', 'output'=>'echo', 'importTo'=>3, )); $x->autoConvert(); </code> |
---|
__construct(array $params) : \XmlToCsv
inherited_from | \XmlToCsv::__construct() |
---|
array
__get(string $name) : mixed
string
name of the element
mixed
value of the element__set(string $name, mixed $value)
string
mixed
autoConvert($map) : mixed
All previously set up paramtere are used to extend the default functionality.
mixed
- string - if $output is set to 'string' and the conversion is OK - bool - otherwise. True on success and false on failureconvert()
convertString()
formatDate(mixed $dateTimeString) : string
mixed
string
datetime in RFC-822 formatimage(mixed $url_or_array, mixed $title, mixed $link) : \XmlToRss
It can be used in 2 different ways: 1. with 3 arguments: $this->image($url,$link,$title) - which sets the required elements of the image tag at once 2. with 1 array argument: $this->image(array $elements), where $elements is a key=>value pair of sub-elements of the image tag with its values
// example 1
$x = new XmlToRss();
$x->image('http://example.com/image.png','http://example.com/image.png','Some image title')
// example 2
$x = new XmlToRss();
$x->image(array(
'url' => 'http://example.com/image.png',
'link' => 'http://example.com/image.png',
'title' => 'Some image title',
'height' => '88'
));
mixed
mixed
mixed
mapConvert()
If $mapping is empty, the previously set parameters and mapping is used. If no mapping was set, the function returns the result as $this->autoConvert()
setParams(array $params_array) : \XmlToCsv
inherited_from | \XmlToCsv::setParams() |
---|
array
$channel : array
$delimiter : string
Only 1 character.
inherited_from | \XmlToCsv::$$delimiter |
---|
$enclosure : string
Only 1 character.
inherited_from | \XmlToCsv::$$enclosure |
---|
$filename : string
$header : bool
inherited_from | \XmlToCsv::$$header |
---|
$importFrom : int
This can be used if you want to export only some items from the XML, not all of them. Defaults to. If used together with $importTo, you can set an interval for selecting specific items from the XML
$importTo : int
This can be used if you want to export only some items from the XML, not all of them Defaults to 999999999. If used together with $importFrom, you can set an interval for selecting specific items from the XML
$item : string
$map : array
By default none of the exported XML nodes are mapped to RSS fields. You have to specify exactly which XML field will be used as which RSS field The whole mapping is used to populate the ITEM elements of the RSS output. The header(=CHANNEL) element is set separatly, and is not mapped from the XML (maybe a todo for a next version)
Example:
-
Text1
Text2
You need to map the XML nodes to different fields, e.g. by passing a mapping to $map:
$this->map = array(
'title' => 'node1',
'description' => 'node2',
)
The array (KEY => VALUE pair) defines which element in the RSS (=KEY) should be filled with which element from the XML (=VALUE). So in the example above - the TITLE element in the RSS will be filled with the value from NODE1 in the XML The example XML would be mapped to the RSS like this:
$output : string
$selectedFields : bool
If FALSE - all fields will be put out
inherited_from | \XmlToCsv::$$selectedFields |
---|
$url : string
If $xml is filled, then $url is ignored
$xml : string
If this is filled, the $url param is ignored