Pb xml

genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006 - 18 févr. 2006 à 15:13
genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006 - 20 févr. 2006 à 16:00
Bonjour
Je n'arrive pas à recuperer mes images d'un fichier xml.
Merci à celui qui pourra aider un malheureux débutant.

mon code :

creation du xml :

for($i= 0;$i<$_SESSION['nbrrubrique'];$i++){
if(isset($_SESSION['vigne'][$i])){
fwrite($create_xml,"<liste>");
for($j=0;$j<count($_SESSION['vigne'][$i]);$j++){if (isset($_SESSION['vigne'][$i][$j])){
fwrite($create_xml,"<vigne>".$_SESSION['vigne'][$i][$j]."</vigne>");
}
else{
fwrite($create_xml,"<vigne>".""."</vigne>");
}
} //fin de for
fwrite($create_xml,"</liste>");
}// fin de if
}

Résultat dans le xml :

<liste>
<vigne>chambre.jpg</vigne>
</liste>
<liste>
<vigne>chambre.jpg</vigne>
<vigne>contact.jpg</vigne>
</liste>
<liste>
<vigne>chambre mini.jpg</vigne>
<vigne>chambre.jpg</vigne>
<vigne>contact.jpg</vigne>
</liste>

Verification :
var_dump($vigne);





array(3) {
[0] =>
object(SimpleXMLElement)#30 (1) {
["vigne"]= >
string(11) "chambre.jpg"
}
[1]=>
object(SimpleXMLElement)#31 (1) {
["vigne"]=>
array(2) {
[0]=>
string(11) "chambre.jpg"
[1]=>
string(11) "contact.jpg"
}
}
[2]=>
object(SimpleXMLElement)#32 (1) {
["vigne"]=>
array(3) {
[0]=>
string(16) "chambre mini.jpg"
[1]=>
string(11) "chambre.jpg"
[2]=>
string(11) "contact.jpg"
}
}
}

Lecture du xml pour recup images :

if(file_exists('test.xml')){
$champs =simplexml_load_file('test.xml');
foreach($champs->valeur as $valeur){
for($i=0;$i<3;$i++){
$vigne[$i]=$valeur->liste[$i];
echo("toto :".$vigne[$i]);
}
}

echo ne renvoie rien .
Je ne vois pas mon erreur.

8 réponses

malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
19 févr. 2006 à 12:14
hello,

déjà, ton flux XML n'est pas valide, sa lecture risque donc d'être compliquée. Il te faut un élément racine. Mais bon :

foreach($champs->valeur as $valeur)

valeur n'existe pas.
Je n'ai pas le temps de tester et de te donner la bonne syntaxe là, je verrai ça demain. Mais ce n'est pas bien compliqué de ttes façons
0
genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006
19 févr. 2006 à 12:36
Bonjour et merci
Je n'ai mis qu'une partie du code; voici l'entete;

$create_xml=fopen('test.xml',"w");
fwrite($create_xml,'<?xml version="1.0" encoding="ISO-8859-1"?>');
fwrite($create_xml,"<champs>rn<valeur>");
.......
for($i=0;$i<$_SESSION['nbrrubrique'];$i++){
if(isset($_SESSION['vigne'][$i])){
fwrite($create_xml,"<liste>");
for($j=0;$j<count($_SESSION['vigne'][$i]);$j++){if (isset($_SESSION['vigne'][$i][$j])){
fwrite($create_xml,"<vigne>".$_SESSION['vigne'][$i][$j]."</vigne>");
}
else{
fwrite($create_xml,"<vigne>".""."</vigne>");
}
} //fin de for
fwrite($create_xml,"</liste>");
}// fin de if
}
..............
fwrite($create_xml,"</valeur>rn</champs>");
0
malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
20 févr. 2006 à 09:55
Donne ton fichier xml en entier stp (ou un epartie mais avec la racine, que je le vois en entier).
0
genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006
20 févr. 2006 à 10:43
Bonjour

le code en entier :

$create_xml= fopen('toto.xml',"w");
fwrite($create_xml,'<?xml version="1.0" encoding="ISO-8859-1"?>');
fwrite($create_xml,"<champs>rn<valeur>");
fwrite($create_xml,"<stylepage>". $_SESSION['stylepage'] ."</stylepage>");
fwrite($create_xml," ". $_SESSION['bordure'] ." ");
fwrite($create_xml,"<stylefond>". $_SESSION['stylefond'] ."</stylefond>");
fwrite($create_xml,"". $_SESSION['photo'] ."

");
fwrite($create_xml,"<listepolice>". $_SESSION['listepolice'] ."</listepolice>");
fwrite($create_xml,"<taillepolice>". $_SESSION['taillepolice'] ."</taillepolice>");
fwrite($create_xml,"<listecouleurnom>". $_SESSION['listecouleurnom'] ."</listecouleurnom>");
fwrite($create_xml,"<stylepolice>". $_SESSION['stylepolice'] ."</stylepolice>");
fwrite($create_xml,"<epaisseurpolice>". $_SESSION['epaisseurpolice'] ."</epaisseurpolice>");
fwrite($create_xml,"<nom>". $_SESSION['nom'] ."</nom>");
fwrite($create_xml,"<nbrrubrique>".$_SESSION['nbrrubrique']."</nbrrubrique>");
for($x =0;$x<$_SESSION['nbrrubrique'];$x++){
fwrite($create_xml,"<rubrique >". $_SESSION['rubrique'][$x] ."</rubrique >");}
for($m=0;$m<$_SESSION['nbrrubrique'];$m++){if(isset($_SESSION['message'][$m])){
fwrite($create_xml,"<message>". $_SESSION['message'][$m] ."</message>");}
else{
fwrite($create_xml,"<message>". "" ."</message>");}}
for($f=0;$f<$_SESSION['nbrrubrique'];$f++){if(isset($_SESSION['fichiers'][$f])){
fwrite($create_xml,"<fichiers>". $_SESSION['fichiers'][$f] ."</fichiers>");}
else{
fwrite($create_xml,"<fichiers>". "" ."</fichiers>");}}
for($t=0;$t<$_SESSION['nbrrubrique'];$t++){if(isset($_SESSION['txt'][$t])){
fwrite($create_xml,"<txt>". $_SESSION['txt'][$t] ."</txt>");}
else{
fwrite($create_xml,"<txt>". "" ."</txt>");}}
for($mi=0;$mi<$_SESSION['nbrrubrique'];$mi++){if(isset($_SESSION['miniature'][$mi])){
fwrite($create_xml,"<miniature>". $_SESSION['miniature'][$mi] ."</miniature>");}
else{
fwrite($create_xml,"<miniature>". "" ."</miniature>");}}

for($i=0;$i<$_SESSION['nbrrubrique'];$i++){
if(isset($_SESSION['vigne'][$i])){
fwrite($create_xml,"<liste>");
for($j=0;$j<count($_SESSION['vigne'][$i]);$j++){if (isset($_SESSION['vigne'][$i][$j])){
fwrite($create_xml,"<vigne>".$_SESSION['vigne'][$i][$j]."</vigne>");
}
else{
fwrite($create_xml,"<vigne>".""."</vigne>");
}
} //fin de for
fwrite($create_xml,"</liste>");
}// fin de if
}
for($c=0;$c<count($_SESSION['choix']);$c++){if(isset($_SESSION['choix'][$c]))
fwrite($create_xml,"<choix>".$_SESSION['choix'][$c]."</choix>");}
fwrite($create_xml,"<raison>". $_SESSION['raison'] ."</raison>");
fwrite($create_xml,"". $_SESSION['adresse']." ");
fwrite($create_xml,"<cpv>". $_SESSION['cpv']." </cpv>");
fwrite($create_xml,"<tel>". $_SESSION['tel']." </tel>");
fwrite($create_xml,"<fax> ".$_SESSION['fax']." </fax>");
fwrite($create_xml,"<mail>". $_SESSION['mail']."</mail>");
fwrite($create_xml,"<site>". $_SESSION['site']." </site>");
fwrite($create_xml,"<listecoulcoord>". $_SESSION['listecoulcoord']." </listecoulcoord>");
fwrite($create_xml,"<rubtaillepolice>". $_SESSION['rubtaillepolice']." </rubtaillepolice>");
fwrite($create_xml,"<rubstylepolice>". $_SESSION['rubstylepolice']." </rubstylepolice>");
fwrite($create_xml,"<rubepaisseurpolice>". $_SESSION['rubepaisseurpolice']." </rubepaisseurpolice>");
fwrite($create_xml,"<rublistepolice>". $_SESSION['rublistepolice']." </rublistepolice>");
fwrite($create_xml,"</valeur>rn</champs>");
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
20 févr. 2006 à 11:34
Non le fichier xml lol
0
genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006
20 févr. 2006 à 12:11
OUPS  !!    pas en forme ce matin :
 

-

  rn

-


  #FFFFFF

  #009933

  #FFFFFF

  chambre.jpg

  Courier New

  20px

  #000000

  italic

  bold

  Cérémonie

  chambre.jpg

  3

  L'apostrophe

  Rub 2

  Rub 3

  cérémonies

 

 

 

  mairie.jpg

 

 

 

  Les mariés

 

 

  maries_0.jpg

-


  chambre mini.jpg

  contact.jpg

  eglise.jpg
 

-


  eglise.jpg

  localisation.jpg
 

-


  eglise.jpg

  hotel.jpg

  localisation.jpg

  mairie.jpg

  maries_0.jpg
 

  m

  f

  v

  nom du gite

  rue du gite

  12345 Ville

  03 22 45 67 76

  03 22 65 98 54

  toto@mail.fr

  www.royalpalace.com

 

  12px

  normal

  normal

  Times New Roman
 
  rn
 
0
malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
20 févr. 2006 à 13:53
<?php
if(file_exists('testxml.xml')){
$xml=simplexml_load_file('testxml.xml');
foreach($xml->valeur as $valeur){
foreach ($valeur -> liste as $vignes) {
foreach ($vignes as $vigne) {
echo 'Vigne => ', $vigne, '
';
}
}
}
}
?>
0
genebaud Messages postés 23 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 20 février 2006
20 févr. 2006 à 16:00
Ok merci j'avais oublié un tour de boucle. Seulement je recupère tout dans un seul tableau; comment puis je reformer mes 3 tableaux ?
0
Rejoignez-nous