DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: XML File I/O

Author:Kasper Skårhøj
Created:2002-11-01T00:32:00
Changed:2005-06-04T21:37:14
Author:Jean-Baptiste RIO
Email:triphot@alliance-francophone.net
Info 3:
Info 4:

EXT: XML File I/O

Extension Key: af_xmlfileio

Copyright 2000-2002, Jean-Baptiste RIO, <triphot@alliance- francophone.net>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.com

Table of Contents

EXT: My Extension 1

Introduction 1

What does it do? 1

Screenshots 1

Users manual 1

FAQ 1

Adminstration 1

FAQ 2

Configuration 2

FAQ 2

Reference 2

Tutorial 2

Known problems 2

To-Do list 2

Changelog 2

Introduction

What does it do?

This extension is a service for saving and loading an XMLfile from/to a PHP array.

Screenshots

N/A

User configuration

load Function

/**

* Load the XML file and parse it in a PHP Array

* performs the service processing

*

* $xmlfile string Full path of the XML file (Optional use setFile instead)

* $conf array Configuration array (Optional)

* @return the PHP array

*/

// XML => PHP

function load($xmlfile='', $conf=array())

save Function

/**

* Save the XML file from a PHP Array

* performs the service processing

*

* $php_array string PHP array to save (Optional use setArray instead)

* $xmlfile string Full path of the XML file (Optional use setFile instead)

* $conf array Configuration array

* @return the save status

*/

// XML => PHP

function save($php_array=array(), $xmlfile='', $conf=array())

setFile Function

/**

* Set file path

*

* $xmlfile string Full path of the XML file

*/

function setFile ($xmlfile='')

setArray Function

/**

* Set php array

*

* $php_array string PHP array to save

*/

function setArray ($php_array='')

setHeader and setFooter Functions

/**

* Allow optional header around the php array data when saving

*

* $section_header string list of open tags (eg <tag1><tag2>...)

*/

function setHeader ($section_header='')

/**

* Allow optional footer around the php array data when saving

*

* $section_footer string list of close tags (eg ...</tag2></tag1>)

*/

function setFooter ($section_footer='')

Example

Example of XML File :

<?xml version="1.0" encoding="iso-8859-1"?>

<game_types>

<str>

<title>Real Time Strategy</title>

<acronym>RTS</acronym>

</str>

<rpg>

<title>Role Playing Game</title>

<acronym>RPG</acronym>

</rpg>

<mmorpg>

<title>Massive Multiplayer Online Role-Playing Game</title>

<acronym>MMORPG</acronym>

</mmorpg>

<sstr>

<title>Real Time Strategic Simulation</title>

<acronym>RTSS</acronym>

</sstr>

</game_types>

Standard result after loading :

Array
(
    [game_types] => Array
        (
            [str] => Array
                (
                    [title] => 'Role Playing Game'
                    [acronym] => 'RTS'
                )
            [rpg] => Array
                (
                    [title] => 'Real Time Strategy'
                    [acronym] => 'RPG'
                )
            [mmorpg] => Array
                (
                    [title] => 'Massive Multiplayer Online Role-Playing Game'
                    [acronym] => 'MMORPG'
                )
            [sstr] => Array
                (
                    [title] => 'Real Time Strategic Simulation'
                    [acronym] => 'SSTR'
                )
        )
)

Administration

This extension is a simple use service.

Typically you use the following code to load the XML file in a PHP array :

if (is_object($xmlservice = t3lib_div::makeInstanceService('xmlExtract'))) {

$xmlservice->setFile($FullFilePath.'myfile.xml');

$php_array = $xmlservice->load();

}

And the following code to save the XML file from a PHP array :

if (is_object($xmlservice = t3lib_div::makeInstanceService('xmlExtract'))) {

$xmlservice->setFile($FullFilePath.'myfile.xml');

$xmlservice->setArray($php_array);

$xmlservice->save();

}

FAQ

N/A

Configuration

The extension allows to load partially the XML file and to encapsulate the PHP Array in a section. Use the Conf parameter as a configuration array.

$conf Array

excludeKeys

Property

excludeKeys

Data type

array

Description

Array of XML tags ignored during the loading.

Example based on the above XML File

conf['excludeKeys'] = Array('rpg','sstr')

php array will be :

Array
(
    [game_types] => Array
        (
            [str] => Array
                (
                    [title] => 'Role Playing Game'
                    [acronym] => 'RTS'
                )
            [mmorpg] => Array
                (
                    [title] => 'Massive Multiplayer Online Role-Playing Game'
                    [acronym] => 'MMORPG'
                )
        )
)

Default

excludeLevels

Property

excludeLevels

Data type

array

Description

Levels of XML tags ignored during loading. Not useful to have an array here but done for further usage

Example based on the above XML File

conf['excludeLevels'] = Array('3')

php array will be :

Array
(
    [game_types] => Array
        (
            [str] => Array
                (
                )
            [rpg] => Array
                (
                )
            [mmorpg] => Array
                (
                )
            [sstr] => Array
                (
                )
        )
)

Default

skipKeys

Property

skipKeys

Data type

array

Description

XML tags to skip eg the content inside the tag replace the tag in the php array. Work only if the tag has child tags.

Example based on the above XML File

conf[skipKeys'] = Array('str', 'mmorpg')

php array will be :

Array
(
    [game_types] => Array
        (
            [title] => 'Role Playing Game'
            [acronym] => 'RTS'
            [rpg] => Array
                (
                    [title] => 'Real Time Strategy'
                    [acronym] => 'RPG'
                )
            [title] => 'Massive Multiplayer Online Role-Playing Game'
            [acronym] => 'MMORPG'
            [sstr] => Array
                (
                    [title] => 'Real Time Strategic Simulation'
                    [acronym] => 'SSTR'
                )
        )
)

Default

skipLevels

Property

skipLevels

Data type

array

Description

Levels of XML file to skip eg all the content inside a tag at the level is levelled up. Work only if the tag has child tags.

Example based on the above XML File

conf['skipLevels'] = Array('1')

php array will be :

Array
(
            [str] => Array
                (
                    [title] => 'Role Playing Game'
                    [acronym] => 'RTS'
                )
            [rpg] => Array
                (
                    [title] => 'Real Time Strategy'
                    [acronym] => 'RPG'
                )
            [mmorpg] => Array
                (
                    [title] => 'Massive Multiplayer Online Role-Playing Game'
                    [acronym] => 'MMORPG'
                )
            [sstr] => Array
                (
                    [title] => 'Real Time Strategic Simulation'
                    [acronym] => 'SSTR'
                )
)

Default

((generated))
Known problems

Only one limitation : the XML File is rewritten. So you have to build the entire content in the php array before saving it (except the main section as explain above)

To-Do list

- Management of sections when saving a php file eg having the possibility to append/modify the XML file and not only rewrite it.

Changelog

- 0.0.1 : First release

img-1 EXT: XML File I/O - 7