Problème PARSER - DomDocument

Petit nouveau ! | 7 Messages

04 janv. 2011, 23:15

Bonjour a tous, je souhaite via une base de donnée créer un document xml.

J'ai deux types de structures, la première est la suivante:

Code : Tout sélectionner

<?xml version="1.0" encoding="UTF-8"?> <GALLERY> <IMAGE FULL="produits/produit1/full_images/image60.jpg" THUMB="produits/produit1/thumbs/thumb60.jpg" LINK="60"/> <IMAGE FULL="produits/produit1/full_images/image59.jpg" THUMB="produits/produit1/thumbs/thumb59.jpg" LINK="59"/> </GALLERY>
et le code php pour le générer est le suivant :
$typeproduit=$_SESSION['produit'];
$xml = "../produit".$typeproduit.".xml"; 
mysql_select_db($database_con_artkitchen, $con_artkitchen);
$query_rs_produit = "SELECT * FROM produit WHERE type ='$typeproduit' ORDER BY placement ASC" ;
$rs_produit = mysql_query($query_rs_produit, $con_artkitchen) or die(mysql_error());
$row_rs_produit = mysql_fetch_assoc($rs_produit);
$totalRows_rs_produit = mysql_num_rows($rs_produit);

$doc = new DOMDocument('1.0', 'UTF-8'); 

$root = $doc->createElement('GALLERY'); 
$doc->appendChild($root); 

do { 
        $full_link = $row_rs_produit['chemin_full'].$row_rs_produit['photo_full'];
	$thumb_link = $row_rs_produit['chemin_thumb'].$row_rs_produit['photo_thumb'];
	$link_link = $row_rs_produit['ID'];

    $root_child = $doc->createElement('IMAGE'); 
    $root->appendChild($root_child); 
    
    $root_attr1 = $doc->createAttribute('FULL'); 
    $root_child->appendChild($root_attr1); 
    
    $root_text = $doc->createTextNode($full_link); 
    $root_attr1->appendChild($root_text); 
    
    $root_attr2= $doc->createAttribute('THUMB'); 
    $root_child->appendChild($root_attr2); 
    
    $root_text = $doc->createTextNode($thumb_link); 
    $root_attr2->appendChild($root_text); 
    
    $root_attr3 = $doc->createAttribute('LINK'); 
    $root_child->appendChild($root_attr3); 
    
    $root_text = $doc->createTextNode($link_link); 
    $root_attr3->appendChild($root_text); 

} while ($row_rs_produit = mysql_fetch_assoc($rs_produit));

$doc->save($xml);
Ceci fonctionne parfaitement.

Maintenant,j'ai besoin d'une structure differente qui est la suivante :

Code : Tout sélectionner

<gallery> <props radius="450" pxspace="20" picwidth="922" picheight="600" /> <col> <tile> <thumb>cyl/thumb/small1_1.jpg</thumb> <pic>cyl/big1_1.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_2.jpg</thumb> <pic>cyl/big1_2.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_3.jpg</thumb> <pic>cyl/big1_3.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_4.jpg</thumb> <pic>cyl/big1_4.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> </col> </gallery>
et voici mon générateur :
$xml = "../gallerycyl.xml";
mysql_select_db($database_con_artkitchen, $con_artkitchen);
$query_rs_galcyl = "SELECT * FROM galcyl ORDER BY ID ASC" ;
$rs_galcyl = mysql_query($query_rs_galcyl, $con_artkitchen) or die(mysql_error());
$row_rs_galcyl = mysql_fetch_assoc($rs_galcyl);
$totalRows_rs_galcyl = mysql_num_rows($rs_galcyl);
echo $totalRows_rs_galcyl;

$doc = new DOMDocument('1.0', 'UTF-8'); 

$root = $doc->createElement('gallery'); 
$doc->appendChild($root);

    $root_child = $doc->createElement('props'); 
    $root->appendChild($root_child); 
    
    $root_attr1 = $doc->createAttribute('radius'); 
    $root_child->appendChild($root_attr1);
	
    $root_text = $doc->createTextNode("450"); 
    $root_attr1->appendChild($root_text);  
	
    $root_attr2= $doc->createAttribute('pxspace'); 
    $root_child->appendChild($root_attr2); 
    
    $root_text = $doc->createTextNode("20"); 
    $root_attr2->appendChild($root_text); 
    
    $root_attr3 = $doc->createAttribute('picwidth'); 
    $root_child->appendChild($root_attr3); 
    
    $root_text = $doc->createTextNode("922"); 
    $root_attr3->appendChild($root_text);  
	
    $root_attr4 = $doc->createAttribute('picheight'); 
    $root_child->appendChild($root_attr4); 
    
    $root_text = $doc->createTextNode("600"); 
    $root_attr4->appendChild($root_text);
	
do { 
	$thumb_link = $row_rs_galcyl['chemin_thumb'].$row_rs_galcyl['image_thumb'];
	$pic_link = $row_rs_galcyl['chemin_ful'].$row_rs_galcyl['image_full'];
	$cap_link = $row_rs_galcyl['descriptif'];
	
	//<col>
	if ($row_rs_galcyl['cpt_col'] == 1) {
		$root_child5 = $doc->createElement('col'); 
         	$root->appendChild($root_child5);
	}
	
	//<tile>
	$root_child6 = $doc->createElement('tile'); 
        $root->appendChild($root_child6);
	
	//<thumb>    
	$root_child7 = $doc->createElement('thumb', $thumb_link); 
        $root->appendChild($root_child7);
	
	//<pic>    
	$root_child8 = $doc->createElement('pics', $pic_link); 
        $root->appendChild($root_child8);
	
	//<cap>    
	$root_child9 = $doc->createElement('cap', $cap_link); 
        $root->appendChild($root_child9);
} while ($row_rs_galcyl = mysql_fetch_assoc($rs_galcyl));
$doc->save($xml);//$dom->save('gallery.xml');

mysql_free_result($rs_galcyl);
Le problème c'est que la pour col et title il ne fait pas l'ouverture et la fermeture correctement c'est à dire <col> .... </col> du coup le fichier ne fonctionne plus quand le flash le lit!!!

Comment celà se fait il ?

Alors que thumb, pic et cap s'ouvre et se ferme bien!!! merci d'avance pour celui , celle ou ceux qui pourront m'aider.

Bonne soirée Eddy-Time

ViPHP
ViPHP | 5462 Messages

05 janv. 2011, 00:01

ton 2eme XML c'est ce que rend ton code ou c'est que tu veux ?

Petit nouveau ! | 7 Messages

05 janv. 2011, 11:35

Bonjour stealth35!

Tout d'abord, merci pour ton aide. Et oui mon deuxième XML c'est ce que je souhaiterais avoir.

Eddy-Time

ViPHP
ViPHP | 5462 Messages

05 janv. 2011, 12:17

Bonjour stealth35!

Tout d'abord, merci pour ton aide. Et oui mon deuxième XML c'est ce que je souhaiterais avoir.

Eddy-Time
et actuelle ca donne quoi avec ton code ?

Petit nouveau ! | 7 Messages

09 janv. 2011, 23:34

Salut stealth35!

Désolé de ne répondre que maintenant, mais je n'avais plus accès au web c'est dernier jour!!

Donc voici ce que mon code génère :

Code : Tout sélectionner

<?xml version="1.0" encoding="UTF-8"?> <gallery> <props radius="450" pxspace="20" picwidth="922" picheight="600"/> <col/> <tile/> <thumb>cyl/thumb/small1_1.jpg</thumb> <pic>big1_1.jpg</pic> <cap>A</cap> <tile/> <thumb>cyl/thumb/small1_2.jpg</thumb> <pic>big1_2.jpg</pic> <cap>B</cap> <tile/> <thumb>cyl/thumb/small1_3.jpg</thumb> <pic>big1_3.jpg</pic> <cap>C</cap> <tile/> <thumb>cyl/thumb/small1_4.jpg</thumb> <pic>big1_4.jpg</pic> <cap>D</cap> <col/> </gallery>
Les PB sont les suivant :

- j'ai <col/> au lieu de <col> pour l'ouverture
- l'ouverture et la fermeture de title ne se fait pas

je remet le résultat souhaiter :

Code : Tout sélectionner

<gallery> <props radius="450" pxspace="20" picwidth="922" picheight="600" /> <col> <tile> <thumb>cyl/thumb/small1_1.jpg</thumb> <pic>cyl/big1_1.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_2.jpg</thumb> <pic>cyl/big1_2.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_3.jpg</thumb> <pic>cyl/big1_3.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> <tile> <thumb>cyl/thumb/small1_4.jpg</thumb> <pic>cyl/big1_4.jpg</pic> <cap>Cuisine pour Thierry Marx</cap> </tile> </col> </gallery>
Encore merci d'avance pour ton aide.

Eddy-Time

ViPHP
ViPHP | 5462 Messages

09 janv. 2011, 23:51

tu devrais créer ton cols hors boucle, sinon ca serai plus visible de faire un while, qu'un do..while

Petit nouveau ! | 7 Messages

10 janv. 2011, 11:05

Oki je teste ça!!! merci pour ta réponse. Et quoi qu'il se passe je reviens vers toi ;-)
Good day

Petit nouveau ! | 7 Messages

10 janv. 2011, 19:10

Donc oki ça fonctionne, c'était juste une histoire d'arborescence. voici le code final :
$xml = "../gallerycyl.xml";
mysql_select_db($database_con_artkitchen, $con_artkitchen);
$query_rs_galcyl = "SELECT * FROM galcyl ORDER BY ID ASC" ;
$rs_galcyl = mysql_query($query_rs_galcyl, $con_artkitchen) or die(mysql_error());
$row_rs_galcyl = mysql_fetch_assoc($rs_galcyl);
$totalRows_rs_galcyl = mysql_num_rows($rs_galcyl);

$doc = new DOMDocument('1.0', 'UTF-8'); 

$root = $doc->createElement('gallery'); 
$doc->appendChild($root);

	$root_child = $doc->createElement('props'); 
    $root->appendChild($root_child); 
    
    $root_attr1 = $doc->createAttribute('radius'); 
    $root_child->appendChild($root_attr1);
	
	$root_text = $doc->createTextNode("450"); 
    $root_attr1->appendChild($root_text);  
	
	$root_attr2= $doc->createAttribute('pxspace'); 
    $root_child->appendChild($root_attr2); 
    
    $root_text = $doc->createTextNode("20"); 
    $root_attr2->appendChild($root_text); 
    
    $root_attr3 = $doc->createAttribute('picwidth'); 
    $root_child->appendChild($root_attr3); 
    
    $root_text = $doc->createTextNode("922"); 
    $root_attr3->appendChild($root_text);  
	
	$root_attr4 = $doc->createAttribute('picheight'); 
    $root_child->appendChild($root_attr4); 
    
    $root_text = $doc->createTextNode("600"); 
    $root_attr4->appendChild($root_text);
	

	
do { 
	$thumb_link = $row_rs_galcyl['chemin_thumb'].$row_rs_galcyl['image_thumb'];
	$pic_link = $row_rs_galcyl['chemin_full'].$row_rs_galcyl['image_full'];
	$cap_link = $row_rs_galcyl['descriptif'];
	
	//<col>
	if ($row_rs_galcyl['cpt_col'] == 1) {
		$root_child5 = $doc->createElement('col'); 
    	$root->appendChild($root_child5);
	}
	
	//<tile>
	$root_child6 = $doc->createElement('tile',''); 
    $root_child5->appendChild($root_child6);
	
	//<thumb>    
	$root_child7 = $doc->createElement('thumb', $thumb_link); 
    $root_child6->appendChild($root_child7);
	
	//<pic>    
	$root_child8 = $doc->createElement('pic', $pic_link); 
    $root_child6->appendChild($root_child8);
	
	//<cap>    
	$root_child9 = $doc->createElement('cap', "<![CDATA[".$cap_link."]]>"); 
    $root_child6->appendChild($root_child9);
	

} while ($row_rs_galcyl = mysql_fetch_assoc($rs_galcyl));

$doc->save($xml);//$dom->save('gallery.xml');
Par contre j'ai une nouvelle erreur maintenant que je pensais resoudre avec le cdata mais j'ai l'erreur suivante :

Code : Tout sélectionner

Warning: DOMDocument::createElement() [function.DOMDocument-createElement]: unterminated entity reference Objet 2010]]> in /htdocs/public/www/BackOffice/galleries.php on line 194
Je pense que c'est parce que j'ai un "&" dans mon texte mais je pensais que cdata le corrigeais!! une petite idée? bonne soirée

Eddy-Time

ViPHP
ViPHP | 5462 Messages

10 janv. 2011, 19:31

ca vient de ton CDATA que tu fais a la main, utilise createCDATASection :wink:

Petit nouveau ! | 7 Messages

11 janv. 2011, 12:42

Je test ça et je te tiens au jus.. Merci ;-)

Petit nouveau ! | 7 Messages

11 janv. 2011, 17:47

Re stealth35!!

Bon oki ça fonctionne mais quand mn flash lit le xml au lieu de m'afficher en legende : hello

Il m'affiche : <![CDATA[hello]]>

Je dois le decoder?

Merci d'avance

ViPHP
ViPHP | 5462 Messages

12 janv. 2011, 12:08

Re stealth35!!

Bon oki ça fonctionne mais quand mn flash lit le xml au lieu de m'afficher en legende : hello

Il m'affiche : <![CDATA[hello]]>

Je dois le decoder?

Merci d'avance
fait un coup de firstchild en plus