<?php
$xml_string = <<<XML
<?xml version='1.0'?>
<log>
<gare Code="17192">
<semaine jour="0">
<train>840800</train>
</semaine>
<semaine jour="0">
<train>2778</train>
</semaine>
<semaine jour="1">
<train>840502</train>
</semaine>
<semaine jour="0">
<train>840600</train>
</semaine>
<semaine jour="1">
<train>5420</train>
</semaine>
<semaine jour="0">
<train>5401</train>
</semaine>
<semaine jour="1">
<train>840501</train>
</semaine>
<semaine jour="1">
<train>840504</train>
</semaine>
<semaine jour="1">
<train>5486</train>
</semaine>
<semaine jour="1">
<train>840601</train>
</semaine>
</gare>
</log>
XML;
// On charge le xml à partir de la chaîne ci-dessous (pour la démo)
/*
Sinon on chargerait le xml à partir d'un fichier, comme ci-dessous
$xml = simplexml_load_file("/chemin/vers/le/fichier.xml");
*/
// Struture globale du xml : log(noeud racine) > gare > semaine > train
foreach($xml->gare as $gare)
{
if(isset($gare["Code"])){ echo "Gare #" . $gare["Code"] . PHP_EOL;
}
foreach($gare->semaine as $semaine)
{
foreach($semaine->train as $train)
{
echo " -> train #" . $train . PHP_EOL;
}
}
}
echo PHP_EOL ;
PD9waHAKJHhtbF9zdHJpbmcgPSA8PDxYTUwKPD94bWwgdmVyc2lvbj0nMS4wJz8+IAo8bG9nPgoJPGdhcmUgQ29kZT0iMTcxOTIiPgoJCTxzZW1haW5lIGpvdXI9IjAiPgoJCQk8dHJhaW4+ODQwODAwPC90cmFpbj4KCQk8L3NlbWFpbmU+CgkJPHNlbWFpbmUgam91cj0iMCI+CgkJCTx0cmFpbj4yNzc4PC90cmFpbj4KCQk8L3NlbWFpbmU+CgkJPHNlbWFpbmUgam91cj0iMSI+CgkJCTx0cmFpbj44NDA1MDI8L3RyYWluPgoJCTwvc2VtYWluZT4KCQk8c2VtYWluZSBqb3VyPSIwIj4KCQkJPHRyYWluPjg0MDYwMDwvdHJhaW4+CgkJPC9zZW1haW5lPgoJCTxzZW1haW5lIGpvdXI9IjEiPgoJCQk8dHJhaW4+NTQyMDwvdHJhaW4+Cgk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