aide xml vers php

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : aide xml vers php

Re: aide xml vers php

par moogli » 05 sept. 2011, 23:36

salut,

a tu testé simplexml ?

par exemple avec
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$xml = <<<xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Root_Element>
   <Element_A>
    <Element_A1>TEXT_A1</Element_A1>
    <Element_A2>TEXT_A2</Element_A2>
    <Element_A3>TEXT_A3</Element_A3>
    <Element_A4>TEXT_A4</Element_A4>
   </Element_A>
   <Element_B>
    <Element_B1>TEXT_B1</Element_B1>
    <Element_B2>TEXT_B2</Element_B2>
    <Element_B3>TEXT_B3</Element_B3>
    <Element_B4>TEXT_B4</Element_B4>
   </Element_B>
</Root_Element>
xml;
$x = simplexml_load_string($xml);
echo '<pre>';
foreach ($x->Element_A as $i => $v) {
    var_dump($i,$v);
    echo '<br />';
}
echo '</pre><hr />';
$sxe = new SimpleXMLElement($xml);
echo $sxe->getName() . "<br />";
foreach ($sxe->Element_A->children() as $child){
    echo $child->getName() . "<br />";
}
?>
tu obtient

Code : Tout sélectionner

string(9) "Element_A" object(SimpleXMLElement)#4 (4) { ["Element_A1"]=> string(7) "TEXT_A1" ["Element_A2"]=> string(7) "TEXT_A2" ["Element_A3"]=> string(7) "TEXT_A3" ["Element_A4"]=> string(7) "TEXT_A4" } Root_Element Element_A1 Element_A2 Element_A3 Element_A4
a toi d'adapter a ton besoin :)

@+

aide xml vers php

par ericdeschamps » 05 sept. 2011, 11:50

bonjour, je voudrais extraire un nom de balise d'un fichier XML pour le mettre dans une variable php

Code : Tout sélectionner

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <Root_Element> <Element_A> <Element_A1>TEXT_A1</Element_A1> <Element_A2>TEXT_A2</Element_A2> <Element_A3>TEXT_A3</Element_A3> <Element_A4>TEXT_A4</Element_A4> </Element_A> <Element_B> <Element_B1>TEXT_B1</Element_B1> <Element_B2>TEXT_B2</Element_B2> <Element_B3>TEXT_B3</Element_B3> <Element_B4>TEXT_B4</Element_B4> </Element_B> </Root_Element>
par exemple je veux récupérer que le nom de balise "Element_B2"et le mettre dans une variable $php quelconque.