[SimpleXML] et recherche d'un élément par son attribut
Bonjour à tous!
Me voilà confronté à un petit problème, voici la structure de mon fichier xml (en simplifié)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <materiel>
<categorie nom="eclairage">
<objet nom="par64" titre="Projecteur PAR de 1000W">
<description>Lorem ipsum dolor sit amet</description>
</objet>
<objet nom="mandarine" titre="Projecteur mandarine de 800W">
<description>Lorem ipsum dolor sit amet</description>
</objet>
</categorie>
<categorie nom="son">
<objet nom=.........>
</objet>
<objet nom=.........>
</objet>
<objet nom=.........>
</objet>
</categorie>
</materiel> |
Donc voilà plus précisément mon problème j'aimerais sélectionner la balise ayant son attribut nom qui soit égal à "par64" par exemple.
Du coup j'appelle ma page materiel_detail.php?nom=par64 avec ce code source dedans :
Code:
1 2 3 4 5 6 7 8 9 10
| <?php
$nom = $_GET['nom'];
$categorie = $_GET['cat'];
$xml = simplexml_load_file("materiel.xml");
$objet = $xml->xpath("//objet[@nom='$nom']");?>
<img src="<?php echo "page/association/materiel/$categorie/$nom.jpg"; ?>" />
<h1><?php echo $objet['titre'];?></h1>
<h2><?php echo $objet->chapo; ?></h2>
<div class="desc"><p><?php echo str_replace("<br />","</p><p>",nl2br($objet->description)); ?></p></div> |
Le problème se situe dans les dernières lignes avec les 4 echos, je n'ai que des erreurs dessus du style : Notice: Undefined index: titre in /Users/Sylvain/Documents/PROJETS/KTarFilms.com/page/association/materiel_details.php on line 13
Quelqu'un sait comment je pourrais m'en sortir?
Merci par avance!!!