Introduction
Introduction – Introduction à XML_Serializer
Introduction à XML_Serializer
XML_Serializer linéarise les structures complexes de données comme les tableaux ou les objets
en documents XML.
Cette classe vous aide à générer tous documents XML désirés sans avoir besoin du DOM.
Actuellement, il y a deux façons dans lesquelles XML_Serializer peut être utilisé dans vos applications :
-
utilisez les fonctionnalités de XML_Serializer pour créer les documents XML dans une
application XML spécifique (e.g. RDF) qui seront traités par un script existant.
-
utilisez les fonctionnalités de XML_Serializer pour linéariser les structures de données
qui doivent être délinéarisées plus tard. Celà est possible en ajoutant les informations
concernant les types dans tous les éléments XML.
Le paquet ne contient pas juste une classe de linéarisation mais aussi une classe
XML_Unserializer, qui est capable de lire virtuellement un document XML et de retourner
une structure de tableau ou d'objet qui représente les données stockées dans le document.
Tutorials sur XML_Serializer
Il y a plusieurs tutoriaux disponible pour XML_Serializer, qui vous aide à débuter.
XML_Serializer (Previous)
|
(Next) Constantes du paquet XML_Serializer
|
|
|
Download Documentation
|
Last updated: Sun, 18 Oct 2009 |
|
Do you think that something on this page is wrong? Please file a bug report or add a note.
|
| User Notes: |
Note by: pear@eric.fambus.nl
To circumvent this problem, you might add the 'mode' => 'simplexml' option to the serializer object. This way, you can use structures like:
'test' => array
(
[0] => array
(
'title' => 'Item 1',
),
[1] => array
(
'title' => 'Item 2',
)
)
This will result in something like
<item>
<title>Item 1</title>
</item>
<item>
<title>Item 2</title>
</item>
Note by: mark_nr@earthlink.net
I spent a lot of time using this package, but it seems that in the end, it inherits limits imposed by arrays. Specifically, I couldn't figure out how to arrange for nested arrays.
For example. I'd like to create the following XML...
<root>
<contact>
<name>Mark</name>
<phoneNumbers>
<dial>5037771001</dial>
<dial>2129711001</dial>
<dial>4455543334</dial>
</phoneNumbers>
</contact>
<contact>
<name>Bob</name>
<phoneNumbers>
<dial>4334553445</dial>
<dial>1001179212</dial>
<dial>6124456669</dial>
</phoneNumbers>
</contact>
</root>
Because an associative array won't allow me to create two ore more elements with the same key, and because (it appears) that I can only have one default element name, I have to choose between multiple <contact>s or multiple <dial> - but not both.
I solved the problem by using the XML functions built into PHP 5 - specifically the SimpleXML class, which doesn't require creating an array, and allows elements to be added line by line.
|
|