Récupérer un element d'un flux xml
Posté : 14 mai 2014, 14:26
Bonjour
J' ai un flux xml de cette forme :
[xml]<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data>
<Testa1>
<Latitude>43.7038854</Latitude>
<Testa1fond>
<Id>6088</Id>
<Name>Nom1</Name>
</Testa1fond>
<Longitude>7.26150383</Longitude>
<Name>Nom2</Name>
</Testa1>
<Testa1>
<Latitude>43.69333308</Latitude>
<Testa1fond>
<Id>6088</Id>
<Name>Nom3</Name>
</Testa1fond>
<Name>Nom4</Name>
</Testa1>
</Data>
</Response>
[/xml]
Et je souhaite juste récupérer les informations dans Name mais que celle du premier niveau c'est a dire :
Nom2
Nom4
Actuellement j’utilise ce que code en php qui marche mais me renvoi tous les Name :
Nom1
Nom2
Nom3
Nom4
Si vous avez une solution.
Merci
J' ai un flux xml de cette forme :
[xml]<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data>
<Testa1>
<Latitude>43.7038854</Latitude>
<Testa1fond>
<Id>6088</Id>
<Name>Nom1</Name>
</Testa1fond>
<Longitude>7.26150383</Longitude>
<Name>Nom2</Name>
</Testa1>
<Testa1>
<Latitude>43.69333308</Latitude>
<Testa1fond>
<Id>6088</Id>
<Name>Nom3</Name>
</Testa1fond>
<Name>Nom4</Name>
</Testa1>
</Data>
</Response>
[/xml]
Et je souhaite juste récupérer les informations dans Name mais que celle du premier niveau c'est a dire :
Nom2
Nom4
Actuellement j’utilise ce que code en php qui marche mais me renvoi tous les Name :
Nom1
Nom2
Nom3
Nom4
$fichier_xml="test.xml";
$dom = new DomDocument;
$dom->load($fichier_xml);
$listePays = $dom->getElementsByTagName('Name');
foreach($listePays as $pays)
echo $pays->firstChild->nodeValue . "<br />";
Malheureusement je ne peux pas toucher au flux xml.Si vous avez une solution.
Merci