« Programmation PHP/Exemples/DomXml » : différence entre les versions

Contenu supprimé Contenu ajouté
m Formatage
DannyS712 (discussion | contributions)
m <source> -> <syntaxhighlight> (phab:T237267)
Ligne 17 :
* Écriture d'un document XML valide à imbrications multiples d'éléments hétéroclites comportant des attributs ou non...
 
<sourcesyntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<root>
Ligne 50 :
<tagNfo id="1" description="description">texteDescription</tagNfo>
</root>
</syntaxhighlight>
</source>
 
* Sauvegarde de ce ''document.xml'' bien formé dans le même répertoire.
Ligne 73 :
** par soucis du détail technique on fera une fonction <code>getAttribute()</code> pour optimiser le code
 
<sourcesyntaxhighlight lang="php">
function getAttribute($node)
{// >((dom)node) ((array)tab)>
Ligne 85 :
return $tab;
}//
</syntaxhighlight>
</source>
 
Description :
Ligne 92 :
On s'attaque ensuite au plus gros du travail de notre convertisseur à savoir <code>domxml2array()</code> :
 
<sourcesyntaxhighlight lang="php">
function domxml2array($node,&$tab,&$i)
{// >((dom)node, (array)tab, (int)i) ((array)tab)>
Ligne 114 :
return $tab;
}//
</syntaxhighlight>
</source>
 
Description :
Ligne 123 :
La fonction utilitaire print_r_html disponible sur php.net permettra de déposer le contenu à l'écran :
 
<sourcesyntaxhighlight lang="php">
function print_r_html($data,$return_data=false)
{
Ligne 137 :
return $data;
}
</syntaxhighlight>
</source>
 
== Création de la classe ==
Ligne 145 :
* On sauvegarde la classe dans <code>DomTree.Class.php</code>.
 
<sourcesyntaxhighlight lang="php">
<?php
 
Ligne 218 :
 
?>
</syntaxhighlight>
</source>
 
== Application ==
Ligne 224 :
Dans un fichier test.php on instancie la classe et on l'exécute:
 
<sourcesyntaxhighlight lang="php">
<?php
 
Ligne 246 :
 
?>
</syntaxhighlight>
</source>
 
== Aperçu ==
On obtient un arbre structuré easy2use pour le web2
 
<sourcesyntaxhighlight lang="php">
Array
(
Ligne 428 :
 
)
</syntaxhighlight>
</source>
 
== En bref ==