IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[SimpleXML] Parser un flux généré par PHP


Sujet :

Bibliothèques et frameworks PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut [SimpleXML] Parser un flux généré par PHP
    Bonjour,

    J'ai tapé ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?php
    $xml = simplexml_load_file('incentivexml.php');
    if ($xml) {
    echo 'lecture fichier XML ok';
    }
    else {
    echo 'erreur de lecture';
    }
    ?>
    Et j'ai les erreurs suivantes :
    Warning: simplexml_load_file() [function.simplexml-load-file]: incentivexml.php:173: parser error : Start tag expected, '<' not found in /home/cashocli/www/testxml.php on line 2

    Warning: simplexml_load_file() [function.simplexml-load-file]: ?> in /home/cashocli/www/testxml.php on line 2

    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/cashocli/www/testxml.php on line 2
    erreur de lecture

    La question que je me pose c'est est-ce que le format de mon fichier xml est incorrect ou est-ce parce que simplexml a besoin d'un fichier xml directement et non pas d'un fichier php qui génère du xml
    Merci de votre réponse

  2. #2
    Membre confirmé
    Avatar de savageman86
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    105
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 105
    Par défaut
    Fichier XML incorrect !

  3. #3
    Membre éclairé
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    Pourtant le résultat est cohérent à l'écran lorsque j'appelle le flux xml
    Je vous colle le source php qui génère le xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    <?php
    	require("include/connection.php");
    	require("include/maintenance.php");
    	$ip=$_SERVER['REMOTE_ADDR'];
    	$url=parse_url($_SERVER['HTTP_REFERER']);
    	$protocole=$url[scheme];
    	$uri=$url[host];
    	if (empty($uri)){
    	$urlsite='';
    	}
    	else {
    	$urlsite=$protocole.'://'.$uri;
    	}
    	header("Content-Type:xml");
    	$pseudo=$_GET['pseudo'];
    $dom=new DOMDocument('1.0', 'iso-8859-1');
    $cashoclic=$dom->appendChild($dom->createElement('CASHOCLIC'));
    	$query2 = "SELECT idpub,type,quantiteutil,quantite,etat,gainpts,lientexte,banniere,largeur,hauteur,html,secondes FROM publicite WHERE type='clicforce' and quantiteutil<quantite and etat='ACTIF' and NOT EXISTS (SELECT id,ip,datevisite FROM visitemembre where visitemembre.id = publicite.idpub and ip='$ip' and datevisite=CURDATE()) order by gainpts desc";
    	$result2 = mysql_query($query2, $connection) or die('error making query');
    	$affected_rows2 = mysql_num_rows($result2);
    	if ($affected_rows2!=0) {
    $clicforce=$cashoclic->appendChild($dom->createElement('CLICINCENTIVE'));
    $total=$clicforce->appendChild($dom->createElement('TOTAL'));
    $total->appendChild($dom->createTextNode($affected_rows2));
    	while  ($data2  =  mysql_fetch_array($result2))  {
    $pub=$clicforce->appendChild($dom->createElement('PUB'));
    //$id=$pub->appendChild($dom->createElement('ID'));
    //$id->appendChild($dom->createTextNode($data2[idpub]));
    	if ($data2[lientexte]==''){
    		 $imgsrc=$pub->appendChild($dom->createElement('IMGSRC'));
    $imgsrc->appendChild($dom->createTextNode($data2[banniere]));
    		 $largeur=$pub->AppendChild($dom->createElement('LARGEUR'));
    $largeur->appendChild($dom->createTextNode($data2[largeur]));
    		 $hauteur=$pub->AppendChild($dom->createElement('HAUTEUR'));
    $hauteur->appendChild($dom->createTextNode($data2[hauteur]));
    	}
    	else {
    		if ($data2[html]==''){
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data2[lientexte])));
    		}
    		else {
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data2[lientexte])));
    		 $desc=$pub->appendChild($dom->createElement('DESC'));
    $desc->AppendChild($dom->createTextNode(utf8_encode($data2[html])));
    		}
    	}
    		 $lien=$pub->appendChild($dom->createElement('LIEN'));
    $lien->AppendChild($dom->createTextNode("$domaine/frame3.php?idpub=$data2[idpub]&pseudo=$pseudo"));
    $secondes=$pub->appendChild($dom->createElement('SECONDES'));
    $secondes->AppendChild($dom->createTextNode(utf8_encode($data2[secondes])));
    }
    }
    	$query3 = "SELECT idpub,type,quantiteutil,quantite,etat,gainpts,lientexte,banniere,largeur,hauteur,html,multiclic FROM publicite WHERE (type='multiclic' or type='multiclicautres') and quantiteutil<quantite and etat='ACTIF' and NOT EXISTS (SELECT id,ip,datevisite FROM visitemembre where visitemembre.id = publicite.idpub and ip='$ip' and datevisite=CURDATE()) order by gainpts desc";
    	$result3 = mysql_query($query3, $connection) or die('error making query');
    	$affected_rows3 = mysql_num_rows($result3);
    	if ($affected_rows3!=0) {
    $multiclic=$cashoclic->appendChild($dom->createElement('MULTICLICINCENTIVE'));
    $total2=$multiclic->appendChild($dom->createElement('TOTAL'));
    $total2->appendChild($dom->createTextNode($affected_rows3));
    	while  ($data3  =  mysql_fetch_array($result3))  {
    $pub=$multiclic->appendChild($dom->createElement('PUB'));
    //$id=$pub->appendChild($dom->createElement('ID'));
    //$id->appendChild($dom->createTextNode($data3[idpub]));
    	if ($data3[lientexte]==''){
    		 $imgsrc=$pub->appendChild($dom->createElement('IMGSRC'));
    $imgsrc->appendChild($dom->createTextNode($data3[banniere]));
    		 $largeur=$pub->AppendChild($dom->createElement('LARGEUR'));
    $largeur->appendChild($dom->createTextNode($data3[largeur]));
    		 $hauteur=$pub->AppendChild($dom->createElement('HAUTEUR'));
    $hauteur->appendChild($dom->createTextNode($data3[hauteur]));
    	}
    	else {
    		if ($data3[html]==''){
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data3[lientexte])));
    		}
    		else {
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data3[lientexte])));
    		 $desc=$pub->appendChild($dom->createElement('DESC'));
    $desc->AppendChild($dom->createTextNode(utf8_encode($data3[html])));
    		}
    	}
    		 $lien=$pub->appendChild($dom->createElement('LIEN'));
    		 if ($data3[type]=='multiclic') {
    $lien->AppendChild($dom->createTextNode("$domaine/framedbclic3.php?idpub=$data3[idpub]&pseudo=$pseudo"));
    $nbclic=$pub->appendChild($dom->createElement('MULTICLIC'));
    $nbclic->AppendChild($dom->createTextNode(utf8_encode($data3[multiclic])));
    }
    else {
    $lien->AppendChild($dom->createTextNode("$domaine/regiexterne3.php?idpub=$data3[idpub]&pseudo=$pseudo"));
    $nbclic=$pub->appendChild($dom->createElement('MULTICLIC'));
    $nbclic->AppendChild($dom->createTextNode("1"));
    }
    }
    }
    	$query4 = "SELECT idpub,type,quantiteutil,quantite,etat,gainpts,lientexte,banniere,largeur,hauteur,html FROM publicite WHERE type='email' and quantiteutil<quantite and etat='ACTIF' and NOT EXISTS (SELECT id,ip,datevisite FROM visitemembre where visitemembre.id = publicite.idpub and ip='$ip' and datevisite=CURDATE()) order by gainpts desc";
    	$result4 = mysql_query($query4, $connection) or die('error making query');
    	$affected_rows4 = mysql_num_rows($result4);
    	if ($affected_rows4!=0) {
    $email=$cashoclic->appendChild($dom->createElement('EMAIL'));
    $total3=$email->appendChild($dom->createElement('TOTAL'));
    $total3->appendChild($dom->createTextNode($affected_rows4));
    	while  ($data4  =  mysql_fetch_array($result4))  {
    $pub=$email->appendChild($dom->createElement('PUB'));
    //$id=$pub->appendChild($dom->createElement('ID'));
    //$id->appendChild($dom->createTextNode($data4[idpub]));
    	if ($data4[lientexte]==''){
    		 $imgsrc=$pub->appendChild($dom->createElement('IMGSRC'));
    $imgsrc->appendChild($dom->createTextNode($data4[banniere]));
    		 $largeur=$pub->AppendChild($dom->createElement('LARGEUR'));
    $largeur->appendChild($dom->createTextNode($data4[largeur]));
    		 $hauteur=$pub->AppendChild($dom->createElement('HAUTEUR'));
    $hauteur->appendChild($dom->createTextNode($data4[hauteur]));
    	}
    	else {
    		if ($data4[html]==''){
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data4[lientexte])));
    		}
    		else {
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data4[lientexte])));
    		 $desc=$pub->appendChild($dom->createElement('DESC'));
    $desc->AppendChild($dom->createTextNode(utf8_encode($data4[html])));
    		}
    	}
    		 $lien=$pub->appendChild($dom->createElement('LIEN'));
    $lien->AppendChild($dom->createTextNode("$domaine/email3.php?idpub=$data4[idpub]&pseudo=$pseudo"));
    }
    }
    	$query5 = "SELECT idpub,type,quantiteutil,quantite,etat,gainpts,lientexte,banniere,largeur,hauteur,html FROM publicite WHERE type='winquizz' and quantiteutil<quantite and etat='ACTIF' and NOT EXISTS (SELECT idpub,ip,date FROM enqueterepondu where enqueterepondu.idpub = publicite.idpub and ip='$ip' and date=CURDATE()) order by gainpts desc";
    	$result5 = mysql_query($query5, $connection) or die('error making query');
    	$affected_rows5 = mysql_num_rows($result5);
    	if ($affected_rows5!=0) {
    $quizz=$cashoclic->appendChild($dom->createElement('QUIZZ'));
    $total3=$quizz->appendChild($dom->createElement('TOTAL'));
    $total3->appendChild($dom->createTextNode($affected_rows5));
    	while  ($data5  =  mysql_fetch_array($result5))  {
    $pub=$quizz->appendChild($dom->createElement('PUB'));
    //$id=$pub->appendChild($dom->createElement('ID'));
    //$id->appendChild($dom->createTextNode($data5[idpub]));
    	if ($data5[lientexte]==''){
    		 $imgsrc=$pub->appendChild($dom->createElement('IMGSRC'));
    $imgsrc->appendChild($dom->createTextNode($data5[banniere]));
    		 $largeur=$pub->AppendChild($dom->createElement('LARGEUR'));
    $largeur->appendChild($dom->createTextNode($data5[largeur]));
    		 $hauteur=$pub->AppendChild($dom->createElement('HAUTEUR'));
    $hauteur->appendChild($dom->createTextNode($data5[hauteur]));
    	}
    	else {
    		if ($data5[html]==''){
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data5[lientexte])));
    		}
    		else {
    		 $lientexte=$pub->appendChild($dom->createElement('LIENTEXTE'));
    $lientexte->AppendChild($dom->createTextNode(utf8_encode($data5[lientexte])));
    		 $desc=$pub->appendChild($dom->createElement('DESC'));
    $desc->AppendChild($dom->createTextNode(utf8_encode($data5[html])));
    		}
    	}
    		 $lien=$pub->appendChild($dom->createElement('LIEN'));
    $lien->AppendChild($dom->createTextNode("$domaine/quizz3.php?idpub=$data5[idpub]&pseudo=$pseudo"));
    }
    }
    mysql_close();
    $dom->formatOutput=True;
    $xml=$dom->saveXML();
    echo $xml;
    ?>
    Merci d'avance

  4. #4
    Membre expérimenté

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Par défaut
    Non mais vous ne pouvez pas faire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $xml = simplexml_load_file('incentivexml.php');
    Vous lisez le code PHP là donc évidemment, ça ne marche pas.

    Il faut que ce code soit interprété donc en passant par le protocole HTTP (requiert allow_url_fopen à On pour pouvoir réaliser cette lecture directement avec simplexml_load_file sinon s'orienter vers un substitut) ou éventuellement, suivant les cas, une inclusion.

Discussions similaires

  1. Flux RSS généré par PHP
    Par skit dans le forum Langage
    Réponses: 4
    Dernier message: 18/01/2009, 17h07
  2. [SimpleXML] Parser du XML dans mon php
    Par onet dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 14/02/2007, 10h09
  3. [SimpleXML] Parser un flux xml avec SimpleXMLElement
    Par DeezerD dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 22/11/2006, 18h07
  4. [MySQL] Récupérer Code HTML généré par PHP
    Par @ngelofdeath dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 26/04/2006, 21h51
  5. [HTML] Scroller un tableau généré par PHP
    Par guy2004 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 11/04/2006, 12h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo