Transformation XML en Liste
Bonjour, Bonsoir,
J'aurais besoin de votre aide car j'ai un petit soucis pour afficher mon XML en liste <li></li> sur mon site avec du Php :)
Voici mon XML
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?xml version="1.0" encoding="UTF-8"?>
<Inventaire>
<Type>
<Nom>Alimentaire
<Produit>Jambon 200g</Produit>
<Produit>Chips 100g</Produit>
<Produit>Eau 6x1L</Produit>
</Nom>
</Type>
<Type>
<Nom>Outillage
<Produit>Marteau</Produit>
<Produit>Clou x250</Produit>
<Produit>Echelle 4m</Produit>
</Nom>
</Type>
</Inventaire> |
et voici le php.
Code:
1 2 3 4 5 6 7 8 9 10 11
| <?php
$fichier = 'inventaire.xml';
$xml = simplexml_load_file($fichier);
foreach ($xml as $Type) {
echo '<h2><a href="#">' . $Type->Nom . '</a></h2><div><ul>';
foreach ($Type as $Nom) {
echo '<li>' . $Nom->Produit . '</li>';
}
echo '</ul></div>';
}
?> |
Le problème étant qu'avec ce code, il m'affiche bien les deux types dans des <h2> mais il ne m'affiche que les premiers produits de chaque type.
Merci d'avance pour votre :)