Parcours fichier xml contenant une sous-rubrique

Bonjour,

Pour les besoins d'un plugin galerie je dois intégrer la gestion des images dans le fichier xml (ordre et nom affiché) le hic est que j'ai un problème pour parcourir le fichier xml que je génère.

Voila la structure que peux avoir le fichier :

[== XML ==]
<?xml version='1.0' encoding='UTF-8'?>
<document>
	<galerie number="0001" active="1" menu="1" user="002" delete="0">
		<name><![CDATA[sculpture]]></name>
		<root_dir><![CDATA[sculpture]]></root_dir>
		<first><![CDATA[1]]></first>
		<parent><![CDATA[]]></parent>
		<extensions><![CDATA[jpg,JPG,jpeg,JPEG]]></extensions>
		<sort><![CDATA[sort]]></sort>
		<prive><![CDATA[]]></prive>
		<password><![CDATA[]]></password>
		<menu_name><![CDATA[Sculpture]]></menu_name>
		<activeSeparateur></activeSeparateur>
		<separateur></separateur>
		<representative></representative>
		<template></template>
		<displayName>1</displayName>
		<displayThumb>1</displayThumb>
		<displaySlideShow></displaySlideShow>
		<content><![CDATA[blabla]]></content>
		<pictures>
		</pictures>
        </galerie>
	<galerie number="0002" active="1" menu="1" user="002" delete="0">
		<name><![CDATA[braise]]></name>
		<root_dir><![CDATA[sculpture/braise]]></root_dir>
		<first><![CDATA[0]]></first>
		<parent><![CDATA[0001]]></parent>
		<extensions><![CDATA[jpg,JPG,jpeg,JPEG]]></extensions>
		<sort><![CDATA[sort]]></sort>
		<prive><![CDATA[]]></prive>
		<password><![CDATA[]]></password>
		<menu_name><![CDATA[Sculpture : "Braise"]]></menu_name>
		<activeSeparateur>0</activeSeparateur>
		<separateur></separateur>
		<representative>braise-04.tb.jpg</representative>
		<template></template>
		<displayName>0</displayName>
		<displayThumb>1</displayThumb>
		<displaySlideShow>0</displaySlideShow>
		<content><![CDATA[]]></content>
		<pictures> 
			<img filename="braise-001.jpg"><![CDATA[braise-001.jpg]]></img>
			<img filename="braise-002.jpg"><![CDATA[braise-002.jpg]]></img>
			<img filename="braise-04.jpg"><![CDATA[braise-04.jpg]]></img>
			<img filename="braise-05.jpg"><![CDATA[braise-05.jpg]]></img>
			<img filename="braise-06.jpg"><![CDATA[braise-06.jpg]]></img>
		</pictures>		
        </galerie>
</document>



Le problème est pour la section "pictures" je n'arrive pas à la parcourir, exemple de code que j'utilise :
[== PHP ==]
	public function getGaleries() {
		$filename = PLX_PLUGINS.'staticgaleries/galeries.xml';
		if(file_exists($filename)) {
			$data = implode('',file($filename));
			$parser = xml_parser_create(PLX_CHARSET);
			xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
			xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
			xml_parse_into_struct($parser,$data,$values,$iTags);
			xml_parser_free($parser);
			if(isset($iTags['galerie']) AND isset($iTags['name'])) {
				$nb = sizeof($iTags['name']);
				$size=ceil(sizeof($iTags['galerie'])/$nb);
				for($i = 0; $i < $nb; $i++) {
					$attributes = $values[$iTags['galerie'][$i*$size]]['attributes'];
					if($attributes['delete'] != 1) {						
						$number = $attributes['number'];
						$this->aGaleries[$number]['name'] = plxUtils::getValue($values[$iTags['name'][$i]]['value']);
						$this->aGaleries[$number]['user'] = $attributes['user'];
						$this->aGaleries[$number]['active'] = intval($attributes['active']);
						$this->aGaleries[$number]['menu'] = intval($attributes['menu']);
						$this->aGaleries[$number]['delete'] = intval($attributes['delete']);
						$this->aGaleries[$number]['first'] = plxUtils::getValue($values[$iTags['first'][$i]]['value']);
						$this->aGaleries[$number]['parent'] = plxUtils::getValue($values[$iTags['parent'][$i]]['value']);
						$this->aGaleries[$number]['root_dir'] = plxUtils::getValue($values[$iTags['root_dir'][$i]]['value']);
						$this->aGaleries[$number]['extensions'] = plxUtils::getValue($values[$iTags['extensions'][$i]]['value']);
						$this->aGaleries[$number]['sort'] = plxUtils::getValue($values[$iTags['sort'][$i]]['value']);
						$this->aGaleries[$number]['prive'] = plxUtils::getValue($values[$iTags['prive'][$i]]['value']);
						$this->aGaleries[$number]['password'] = plxUtils::getValue($values[$iTags['password'][$i]]['value']);
						$this->aGaleries[$number]['menu_name'] = plxUtils::getValue($values[$iTags['menu_name'][$i]]['value']);
						$this->aGaleries[$number]['activeSeparateur'] = plxUtils::getValue($values[$iTags['activeSeparateur'][$i]]['value']);
						$this->aGaleries[$number]['separateur'] = plxUtils::getValue($values[$iTags['separateur'][$i]]['value']);
						$this->aGaleries[$number]['representative'] = plxUtils::getValue($values[$iTags['representative'][$i]]['value']);
						$this->aGaleries[$number]['template'] = plxUtils::getValue($values[$iTags['template'][$i]]['value']);
						$this->aGaleries[$number]['displayName'] = plxUtils::getValue($values[$iTags['displayName'][$i]]['value']);
						$this->aGaleries[$number]['displayThumb'] = plxUtils::getValue($values[$iTags['displayThumb'][$i]]['value']);
						$this->aGaleries[$number]['displaySlideShow'] = plxUtils::getValue($values[$iTags['displaySlideShow'][$i]]['value']);										
						$this->aGaleries[$number]['content'] = plxUtils::getValue($values[$iTags['content'][$i]]['value']);
						
						if(isset($iTags['pictures'])) {
							$nb_pic = sizeof($iTags['pictures']);
							$size_pic = ceil(sizeof($iTags['pictures'])/$nb_pic);
							for($p = 0; $p < $nb_pic; $p++) {
								$attributes_pic = $values[$iTags['galerie'][$i*$size]]['pictures'][$p*$size_pic]['attributes'];
								echo $attributes_pic['filename'].' - '.plxUtils::getValue($values[$iTags['pictures'][$p]]['value']);
							}
						}
					}
				}
			}
		}	
	}


Si vous avez une idée ou une piste je suis preneur.
Merci.

J'ai un string de l'array

Réponses

  • Bonjour,

    Bon j'ai avancé sur mon problème. Toujours sur la même base xml j'ai ce code php qui fonctionne presque.
    [== PHP ==]
    	public function getGaleries() {
    		$filename = PLX_PLUGINS.'staticgaleries/galeries.xml';
    		if(file_exists($filename)) {
    			$data = implode('',file($filename));
    			$parser = xml_parser_create(PLX_CHARSET);
    			xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
    			xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
    			xml_parse_into_struct($parser,$data,$values,$iTags);			
    			xml_parser_free($parser);
    			if(isset($iTags['galerie']) AND isset($iTags['name'])) {
    				$nb = sizeof($iTags['name']);
    				$size=ceil(sizeof($iTags['galerie'])/$nb);
    				for($i = 0; $i < $nb; $i++) {
    					$attributes = $values[$iTags['galerie'][$i*$size]]['attributes'];
    					if($attributes['delete'] != 1) {						
    						$number = $attributes['number'];
    						$this->aGaleries[$number]['name'] = plxUtils::getValue($values[$iTags['name'][$i]]['value']);
    						$this->aGaleries[$number]['user'] = $attributes['user'];
    						$this->aGaleries[$number]['active'] = intval($attributes['active']);
    						$this->aGaleries[$number]['menu'] = intval($attributes['menu']);
    						//$this->aGaleries[$number]['menu_position'] = intval($attributes['menu_position']);
    						$this->aGaleries[$number]['delete'] = intval($attributes['delete']);
    						$this->aGaleries[$number]['first'] = plxUtils::getValue($values[$iTags['first'][$i]]['value']);
    						$this->aGaleries[$number]['parent'] = plxUtils::getValue($values[$iTags['parent'][$i]]['value']);
    						$this->aGaleries[$number]['root_dir'] = plxUtils::getValue($values[$iTags['root_dir'][$i]]['value']);
    						$this->aGaleries[$number]['extensions'] = plxUtils::getValue($values[$iTags['extensions'][$i]]['value']);
    						$this->aGaleries[$number]['sort'] = plxUtils::getValue($values[$iTags['sort'][$i]]['value']);
    						$this->aGaleries[$number]['prive'] = plxUtils::getValue($values[$iTags['prive'][$i]]['value']);
    						$this->aGaleries[$number]['password'] = plxUtils::getValue($values[$iTags['password'][$i]]['value']);
    						$this->aGaleries[$number]['menu_name'] = plxUtils::getValue($values[$iTags['menu_name'][$i]]['value']);
    						$this->aGaleries[$number]['activeSeparateur'] = plxUtils::getValue($values[$iTags['activeSeparateur'][$i]]['value']);
    						$this->aGaleries[$number]['separateur'] = plxUtils::getValue($values[$iTags['separateur'][$i]]['value']);
    						$this->aGaleries[$number]['representative'] = plxUtils::getValue($values[$iTags['representative'][$i]]['value']);
    						$this->aGaleries[$number]['template'] = plxUtils::getValue($values[$iTags['template'][$i]]['value']);
    						$this->aGaleries[$number]['displayName'] = plxUtils::getValue($values[$iTags['displayName'][$i]]['value']);
    						$this->aGaleries[$number]['displayThumb'] = plxUtils::getValue($values[$iTags['displayThumb'][$i]]['value']);
    						$this->aGaleries[$number]['displaySlideShow'] = plxUtils::getValue($values[$iTags['displaySlideShow'][$i]]['value']);										
    						$this->aGaleries[$number]['content'] = plxUtils::getValue($values[$iTags['content'][$i]]['value']);
    						
    						//echo '<pre>';
    						if(isset($iTags['pictures'])) {
    							$nb_pic = sizeof($iTags['img']);
    							$size_pic = ceil(sizeof($iTags['pictures'])/$nb_pic);
    							for($p = 0; $p < $nb_pic; $p++) {
    								if(isset($iTags['img'])) {
    									$attributes_pic = $values[$iTags['img'][$p]]['attributes'];
    									$this->aGaleries[$number]['pictures'][$attributes_pic['filename']]['name'] = plxUtils::getValue($values[$iTags['img'][$p]]['value']);
    								}
    							}
    						}
    						//echo '</pre>';
    					}
    				}
    			}
    		}
    		echo '<pre>';
    		print_r($this->aGaleries);
    		echo '</pre>';
    	}
    

    Il y a qu'un problème, le tableau contient la sous-rubrique xml pictures mais dans les deux galeries alors que seul la 2eme devrait en avoir une :
    [== XML ==]
    Array
    (
        [0001] => Array
            (
                [name] => sculpture
                [user] => 002
                [active] => 1
                [menu] => 1
                [delete] => 0
                [first] => 1
                [parent] => 
                [root_dir] => sculpture
                [extensions] => jpg,JPG,jpeg,JPEG
                [sort] => sort
                [prive] => 
                [password] => 
                [menu_name] => Sculpture
                [activeSeparateur] => 
                [separateur] => 
                [representative] => 
                [template] => 
                [displayName] => 1
                [displayThumb] => 1
                [displaySlideShow] => 
                [content] =>
                [pictures] => Array
                    (
                        [braise-001.jpg] => Array
                            (
                                [name] => braise-0000001.jpg
                            )
                        [braise-002.jpg] => Array
                            (
                                [name] => braise-002.jpg
                            )
                        [braise-04.jpg] => Array
                            (
                                [name] => braise-04.jpg
                            )
                        [braise-05.jpg] => Array
                            (
                                [name] => braise-05.jpg
                            )
                        [braise-06.jpg] => Array
                            (
                                [name] => braise-06.jpg
                            )
                    )
            )
    
        [0002] => Array
            (
                [name] => braise
                [user] => 002
                [active] => 1
                [menu] => 1
                [delete] => 0
                [first] => 
                [parent] => 0001
                [root_dir] => sculpture/braise
                [extensions] => jpg,JPG,jpeg,JPEG
                [sort] => sort
                [prive] => 
                [password] => 
                [menu_name] => Sculpture : "Braise"
                [activeSeparateur] => 
                [separateur] => 
                [representative] => braise-04.tb.jpg
                [template] => 
                [displayName] => 
                [displayThumb] => 1
                [displaySlideShow] => 
                [content] => 
                [pictures] => Array
                    (
                        [braise-001.jpg] => Array
                            (
                                [name] => braise-0000001.jpg
                            )
                        [braise-002.jpg] => Array
                            (
                                [name] => braise-002.jpg
                            )
                        [braise-04.jpg] => Array
                            (
                                [name] => braise-04.jpg
                            )
                        [braise-05.jpg] => Array
                            (
                                [name] => braise-05.jpg
                            )
                        [braise-06.jpg] => Array
                            (
                                [name] => braise-06.jpg
                            )
                    )
            )
    )
    

    J'ai un string de l'array

  • Fais un print_r de $values et $iTags. Et affiche nous le résultat.
  • print_r($values)
    [== PHP ==]
    Array
    (
        [0] => Array
            (
                [tag] => document
                [type] => open
                [level] => 1
                [value] => 
    	
            )
    
        [1] => Array
            (
                [tag] => galerie
                [type] => open
                [level] => 2
                [attributes] => Array
                    (
                        [number] => 0001
                        [active] => 1
                        [menu] => 1
                        [user] => 002
                        [delete] => 0
                    )
    
                [value] => 
    		
            )
    
        [2] => Array
            (
                [tag] => name
                [type] => complete
                [level] => 3
                [value] => sculpture
            )
    
        [3] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [4] => Array
            (
                [tag] => root_dir
                [type] => complete
                [level] => 3
                [value] => sculpture
            )
    
        [5] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [6] => Array
            (
                [tag] => first
                [type] => complete
                [level] => 3
                [value] => 1
            )
    
        [7] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [8] => Array
            (
                [tag] => parent
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [9] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [10] => Array
            (
                [tag] => extensions
                [type] => complete
                [level] => 3
                [value] => jpg,JPG,jpeg,JPEG
            )
    
        [11] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [12] => Array
            (
                [tag] => sort
                [type] => complete
                [level] => 3
                [value] => sort
            )
    
        [13] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [14] => Array
            (
                [tag] => prive
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [15] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [16] => Array
            (
                [tag] => password
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [17] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [18] => Array
            (
                [tag] => menu_name
                [type] => complete
                [level] => 3
                [value] => Sculpture
            )
    
        [19] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [20] => Array
            (
                [tag] => activeSeparateur
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [21] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [22] => Array
            (
                [tag] => separateur
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [23] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [24] => Array
            (
                [tag] => representative
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [25] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [26] => Array
            (
                [tag] => template
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [27] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [28] => Array
            (
                [tag] => displayName
                [type] => complete
                [level] => 3
                [value] => 1
            )
    
        [29] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [30] => Array
            (
                [tag] => displayThumb
                [type] => complete
                [level] => 3
                [value] => 1
            )
    
        [31] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [32] => Array
            (
                [tag] => displaySlideShow
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [33] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [34] => Array
            (
                [tag] => content
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [35] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [36] => Array
            (
                [tag] => pictures
                [type] => complete
                [level] => 3
                [value] => 
    		
            )
    
        [37] => Array
            (
                [tag] => galerie
                [value] => 
    	
                [type] => cdata
                [level] => 2
            )
    
        [38] => Array
            (
                [tag] => galerie
                [type] => close
                [level] => 2
            )
    
        [39] => Array
            (
                [tag] => document
                [value] => 
    	
                [type] => cdata
                [level] => 1
            )
    
        [40] => Array
            (
                [tag] => galerie
                [type] => open
                [level] => 2
                [attributes] => Array
                    (
                        [number] => 0002
                        [active] => 1
                        [menu] => 1
                        [user] => 002
                        [delete] => 0
                    )
    
                [value] => 
    		
            )
    
        [41] => Array
            (
                [tag] => name
                [type] => complete
                [level] => 3
                [value] => braise
            )
    
        [42] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [43] => Array
            (
                [tag] => root_dir
                [type] => complete
                [level] => 3
                [value] => sculpture/braise
            )
    
        [44] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [45] => Array
            (
                [tag] => first
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [46] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [47] => Array
            (
                [tag] => parent
                [type] => complete
                [level] => 3
                [value] => 0001
            )
    
        [48] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [49] => Array
            (
                [tag] => extensions
                [type] => complete
                [level] => 3
                [value] => jpg,JPG,jpeg,JPEG
            )
    
        [50] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [51] => Array
            (
                [tag] => sort
                [type] => complete
                [level] => 3
                [value] => sort
            )
    
        [52] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [53] => Array
            (
                [tag] => prive
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [54] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [55] => Array
            (
                [tag] => password
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [56] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [57] => Array
            (
                [tag] => menu_name
                [type] => complete
                [level] => 3
                [value] => Sculpture : "Braise"
            )
    
        [58] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [59] => Array
            (
                [tag] => activeSeparateur
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [60] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [61] => Array
            (
                [tag] => separateur
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [62] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [63] => Array
            (
                [tag] => representative
                [type] => complete
                [level] => 3
                [value] => braise-04.tb.jpg
            )
    
        [64] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [65] => Array
            (
                [tag] => template
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [66] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [67] => Array
            (
                [tag] => displayName
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [68] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [69] => Array
            (
                [tag] => displayThumb
                [type] => complete
                [level] => 3
                [value] => 1
            )
    
        [70] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [71] => Array
            (
                [tag] => displaySlideShow
                [type] => complete
                [level] => 3
                [value] => 0
            )
    
        [72] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [73] => Array
            (
                [tag] => content
                [type] => complete
                [level] => 3
                [value] => 
            )
    
        [74] => Array
            (
                [tag] => galerie
                [value] => 
    		
                [type] => cdata
                [level] => 2
            )
    
        [75] => Array
            (
                [tag] => pictures
                [type] => open
                [level] => 3
                [value] => 
    			
            )
    
        [76] => Array
            (
                [tag] => img
                [type] => complete
                [level] => 4
                [attributes] => Array
                    (
                        [filename] => braise-001.jpg
                    )
    
                [value] => braise-0000001.jpg
            )
    
        [77] => Array
            (
                [tag] => pictures
                [value] => 
    			
                [type] => cdata
                [level] => 3
            )
    
        [78] => Array
            (
                [tag] => img
                [type] => complete
                [level] => 4
                [attributes] => Array
                    (
                        [filename] => braise-002.jpg
                    )
    
                [value] => braise-002.jpg
            )
    
        [79] => Array
            (
                [tag] => pictures
                [value] => 
    			
                [type] => cdata
                [level] => 3
            )
    
        [80] => Array
            (
                [tag] => img
                [type] => complete
                [level] => 4
                [attributes] => Array
                    (
                        [filename] => braise-04.jpg
                    )
    
                [value] => braise-04.jpg
            )
    
        [81] => Array
            (
                [tag] => pictures
                [value] => 
    			
                [type] => cdata
                [level] => 3
            )
    
        [82] => Array
            (
                [tag] => img
                [type] => complete
                [level] => 4
                [attributes] => Array
                    (
                        [filename] => braise-05.jpg
                    )
    
                [value] => braise-05.jpg
            )
    
        [83] => Array
            (
                [tag] => pictures
                [value] => 
    			
                [type] => cdata
                [level] => 3
            )
    
        [84] => Array
            (
                [tag] => img
                [type] => complete
                [level] => 4
                [attributes] => Array
                    (
                        [filename] => braise-06.jpg
                    )
    
                [value] => braise-06.jpg
            )
    
        [85] => Array
            (
                [tag] => pictures
                [value] => 		
    		
                [type] => cdata
                [level] => 3
            )
    
        [86] => Array
            (
                [tag] => pictures
                [type] => close
                [level] => 3
            )
    
        [87] => Array
            (
                [tag] => galerie
                [value] => 
    	
                [type] => cdata
                [level] => 2
            )
    
        [88] => Array
            (
                [tag] => galerie
                [type] => close
                [level] => 2
            )
    
        [89] => Array
            (
                [tag] => document
                [value] => 
    
                [type] => cdata
                [level] => 1
            )
    
        [90] => Array
            (
                [tag] => document
                [type] => close
                [level] => 1
            )
    
    )
    

    print_r($iTags);
    [== PHP ==]
    Array
    (
        [document] => Array
            (
                [0] => 0
                [1] => 39
                [2] => 89
                [3] => 90
            )
    
        [galerie] => Array
            (
                [0] => 1
                [1] => 3
                [2] => 5
                [3] => 7
                [4] => 9
                [5] => 11
                [6] => 13
                [7] => 15
                [8] => 17
                [9] => 19
                [10] => 21
                [11] => 23
                [12] => 25
                [13] => 27
                [14] => 29
                [15] => 31
                [16] => 33
                [17] => 35
                [18] => 37
                [19] => 38
                [20] => 40
                [21] => 42
                [22] => 44
                [23] => 46
                [24] => 48
                [25] => 50
                [26] => 52
                [27] => 54
                [28] => 56
                [29] => 58
                [30] => 60
                [31] => 62
                [32] => 64
                [33] => 66
                [34] => 68
                [35] => 70
                [36] => 72
                [37] => 74
                [38] => 87
                [39] => 88
            )
    
        [name] => Array
            (
                [0] => 2
                [1] => 41
            )
    
        [root_dir] => Array
            (
                [0] => 4
                [1] => 43
            )
    
        [first] => Array
            (
                [0] => 6
                [1] => 45
            )
    
        [parent] => Array
            (
                [0] => 8
                [1] => 47
            )
    
        [extensions] => Array
            (
                [0] => 10
                [1] => 49
            )
    
        [sort] => Array
            (
                [0] => 12
                [1] => 51
            )
    
        [prive] => Array
            (
                [0] => 14
                [1] => 53
            )
    
        [password] => Array
            (
                [0] => 16
                [1] => 55
            )
    
        [menu_name] => Array
            (
                [0] => 18
                [1] => 57
            )
    
        [activeSeparateur] => Array
            (
                [0] => 20
                [1] => 59
            )
    
        [separateur] => Array
            (
                [0] => 22
                [1] => 61
            )
    
        [representative] => Array
            (
                [0] => 24
                [1] => 63
            )
    
        [template] => Array
            (
                [0] => 26
                [1] => 65
            )
    
        [displayName] => Array
            (
                [0] => 28
                [1] => 67
            )
    
        [displayThumb] => Array
            (
                [0] => 30
                [1] => 69
            )
    
        [displaySlideShow] => Array
            (
                [0] => 32
                [1] => 71
            )
    
        [content] => Array
            (
                [0] => 34
                [1] => 73
            )
    
        [pictures] => Array
            (
                [0] => 36
                [1] => 75
                [2] => 77
                [3] => 79
                [4] => 81
                [5] => 83
                [6] => 85
                [7] => 86
            )
    
        [img] => Array
            (
                [0] => 76
                [1] => 78
                [2] => 80
                [3] => 82
                [4] => 84
            )
    )
    

    J'ai un string de l'array

  • Jerry WhamJerry Wham Member
    janvier 2014 modifié
    Modifie ton fichier xml de manière à avoir :
    <pictures> 
    			<img filename="braise-001.jpg" pict-gallerie="0002"><![CDATA[braise-001.jpg]]></img>
    			<img filename="braise-002.jpg" pict-gallerie="0002"><![CDATA[braise-002.jpg]]></img>
    			<img filename="braise-04.jpg" pict-gallerie="0002"><![CDATA[braise-04.jpg]]></img>
    			<img filename="braise-05.jpg" pict-gallerie="0002"><![CDATA[braise-05.jpg]]></img>
    			<img filename="braise-06.jpg" pict-gallerie="0002"><![CDATA[braise-06.jpg]]></img>
    		</pictures>
    
    Ensuite remplace au niveau de ton parser, les lignes :
    //echo '<pre>';
    						if(isset($iTags['pictures'])) {
    							$nb_pic = sizeof($iTags['img']);
    							$size_pic = ceil(sizeof($iTags['pictures'])/$nb_pic);
    							for($p = 0; $p < $nb_pic; $p++) {
    								if(isset($iTags['img'])) {
    									$attributes_pic = $values[$iTags['img'][$p]]['attributes'];
    									$this->aGaleries[$number]['pictures'][$attributes_pic['filename']]['name'] = plxUtils::getValue($values[$iTags['img'][$p]]['value']);
    								}
    							}
    						}
    						//echo '</pre>';
    
    par
    $count = count($values)
    $aGaleries[$number]['pictures'] = array();
    						for ($j=0; $j < $count; $j++) { 
    							if (isset($values[$j]['attributes'])) {
    								$file =  getValue($values[$j]['attributes']['filename']);
    								$gal =  getValue($values[$j]['attributes']['pict-gallerie']);
    								$name =  getValue($values[$j]['value']);
    								if (!empty($file) && $gal == $number) {
    									$aGaleries[$number]['pictures'][$file]['name'] = $name;
    								}
    							}
    						}	
    
    Tu devrais obtenir ce que tu veux.
  • flipflipflipflip Member
    février 2014 modifié
    Parfait ça marche nikel... J'ai fais quelques petites corrections :
    [== XML ==]
    		<pictures>
    			<img filename="braise-001.jpg" pict-galerie="0002"><![CDATA[braise-0000001.jpg]]></img>
    			<img filename="braise-002.jpg" pict-galerie="0002"><![CDATA[braise-002.jpg]]></img>
    			<img filename="braise-04.jpg" pict-galerie="0002"><![CDATA[braise-04.jpg]]></img>
    			<img filename="braise-05.jpg" pict-galerie="0002"><![CDATA[braise-05.jpg]]></img>
    			<img filename="braise-06.jpg" pict-galerie="0002"><![CDATA[braise-06.jpg]]></img>		
    		</pictures>
    

    [== PHP ==]
    $count = count($values);
    $this->aGaleries[$number]['pictures'] = array();
    for($j=0;$j<$count;$j++) { 
    	if(isset($values[$j]['attributes'])) {
    		$filename = plxUtils::getValue($values[$j]['attributes']['filename']);
    		$galerie = plxUtils::getValue($values[$j]['attributes']['pict-galerie']);
    		$name = plxUtils::getValue($values[$j]['value']);
    		if(!empty($filename) && $galerie == $number) {
    			$this->aGaleries[$number]['pictures'][$filename]['name'] = $name;
    		}
    	}
    }
    

    Merci

    J'ai un string de l'array

  • Je n'ai pas utilisé $filename car la variable est déjà utilisée en début de script.
    De plus, il vaut mieux définir $aGaleries[$number] = array(); car si tu ne le fais pas, tu peux avoir des bugs qui peuvent apparaître dans des scripts liés aux résultats (affichage de pictures par exemple) ou tri des pictures, etc...

    Pour les plxUtils et les $this oubliés, c'est parce que j'avais réécrit une fonction indépendante de pluxml pour éviter d'avoir à tout charger pour faire les tests.
  • Ok ça marche pil poil, encore merci pour ton aide.

    J'ai un string de l'array

Connectez-vous ou Inscrivez-vous pour répondre.