[SimpleXML] Enfant avec plusieurs enfants
je m'explique:
voici une portion de mon xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <VodItem id="4" rsac="33620226" score="0" released="2010-04-29T00:00:00" until="2010-12-31T00:00:00" year="1983" duration="120" category="Cinema" type="Long métrage" nationality="France" language_vo="Français" newrelease="0" ratingid="2" note_spectateurs="2.90">
<Copyright>© 1983 Pathé Renn Production - Adel - T. Films</Copyright>
<Title_vo>Le Battant</Title_vo>
<ShortTitle_vo>Battant</ShortTitle_vo>
<Title>Le Battant</Title>
<ShortTitle>Battant</ShortTitle>
<Directors>
<Director id="236">Alain Delon</Director>
</Directors>
<Actors>
<Actor id="257" rank="2">Anne Parillaud</Actor>
<Actor id="236" rank="1">Alain Delon</Actor>
<Actor id="251" rank="0">Andréa Ferréol</Actor>
<Actor id="367" rank="0">François Périer</Actor>
<Actor id="571" rank="0">Pierre Mondy</Actor>
<Actor id="2695" rank="0">Richard Anconina</Actor>
</Actors>
</VodItem> |
Je traite ce xml.
Je veux recuperer certaine informations, pour cela je fait :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| //Recuperation du fichier XML
$xmlData=simplexml_load_file('monXML.xml');
foreach ($xmlData->children() as $node)
{
$arr = $node->attributes();
foreach ($node->Actors->children() as $nodeActors)
{
$arr2 = $nodeActors->attributes();
// Ajouter les noeuds
$item = $xml->addChild("Item");
$item->addChild("Title",($node->Title));
$item->addChild("Description",($node->Description));
$prod = $item->addChild("Director",($node->Director));
$actor = $item->addChild("Actor",($nodeActors->Actors));
// Ajout d'attributs
//For item
$item->addAttribute("id",$arr["id"]);
$item->addAttribute("Year",$arr["year"]);
$item->addAttribute("Category",$arr["category"]);
//For Acteur
$actor->addAttribute("id",$arr2["id"]);
}
}}
header("Content-type: text/xml");
// print the SimpleXMLElement as a XML well-formed string
echo $xml->asXML(); |
Dans un premier temps je fais une boucle pour récupérer mes données,
je fait une deuxièmes boucle pour récupérer les noms et id de mes acteurs.
Seules probleme en sortie cela me créé bien un fichier xml mais pas avec un seul Item, mais cela me fait 6 items du meme films car il y a 6 acteurs.
je voudrais faire un seule items avec mes 6 acteur comme dans mon premier xml.
Merci bonne journée