Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Flash/Flex > Flash > AS3
AS3 Questions relatives à la programmation ActionScript 3 (Cours AS3)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/12/2011, 19h55   #1
Invité de passage
 
Inscription : novembre 2003
Messages : 10
Détails du profil
Informations forums :
Inscription : novembre 2003
Messages : 10
Points : 2
Points : 2
Par défaut Traitement d'un fichier XML

Bonjour,
J’ai besoin d’aide pour parcourir un fichier xml.
Je ne sais pas ou le problème soit le fichier xml qui est mal structurer ou bien c’est mon programme
Meri d’avance pour votre aide je n’arrive pas a affiché le chapitre 3
Fichier xml :
Code :
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
 
<?xml version="1.0" encoding="utf-8"?>
<chapitre0>
	<chapitre1>
		<chap1>1.titre	livre 01</chap1>
		<chapitre2>
			<chap2>1.1.titre	</chap2>
				<chapitre3>
					<chap3>1.1.1.titre	</chap3>
					<chap3>1.1.2.titre	</chap3>
				</chapitre3>
			<chap2>1.2.titre	</chap2>
				<chapitre3>
					<chap3>1.2.1.titre	</chap3>
					<chap3>1.2.2.titre	</chap3>
				</chapitre3>
		</chapitre2>
	</chapitre1>
	<chapitre1>
		<chap1>2.titre	livre 02</chap1>
		<chapitre2>
			<chap2>2.1.titre	</chap2>
				<chapitre3>
					<chap3>2.1.1.titre	</chap3>
					<chap3>2.1.2.titre	</chap3>
					<chap3>2.1.3.titre	</chap3>
				</chapitre3>
			<chap2>2.2.titre	</chap2>
				<chapitre3>
					<chap3>2.2.1.titre	</chap3>
					<chap3>2.2.2.titre	</chap3>
					<chap3>2.2.3.titre	</chap3>
				</chapitre3>
		</chapitre2>
	</chapitre1>
</chapitre0>
Le source:
Code :
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
 
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
//
var chargementXML:URLLoader = new URLLoader();// objet de chargement
var fichier:URLRequest = new URLRequest("chapitres.xml");// url du fichier chargé
chargementXML.addEventListener( Event.COMPLETE, chargementComplet );
chargementXML.load( fichier );
 
// chargement terminé du fichier xml;
function chargementComplet(pEvt:Event):void
{
	// on récupère notre xml
	var wXML:XML = new XML(pEvt.target.data);
	var chapitre:XMLList = wXML.elements();
 
	//Chapitre 01
	var xl1:XMLList = wXML.chapitre1.chap1;
	for (var i:int = 0; i < xl1.length(); i++) 
	{ 
		var titre01:XML = xl1[i]; 
		trace(titre01); 
		//Chapitre 02
		var xl2:XMLList = wXML.chapitre1.chapitre2[i].chap2;
		for (var j:int = 0; j < xl2.length(); j++) 
		{ 
			var titre02:XML = xl2[j]; 
			trace("   "+titre02); 
			//Chapitre 03
			var xl3:XMLList = wXML.chapitre1.chapitre2.chapitre3[j].chap3;
			for (var k:int = 0; k < xl3.length(); k++) 
			{ 
				var titre03:XML = xl3[k]; 
				trace("   "+"   "+titre03);				
			} 
		} 
	} 
 
}
mebarkia est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/01/2012, 09h28   #2
Nouveau Membre du Club
 
Développeur informatique
Inscription : septembre 2006
Messages : 139
Détails du profil
Informations personnelles :
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : septembre 2006
Messages : 139
Points : 32
Points : 32
Supprime l'espace et le saut de ligne au début de ton xml
lecra est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h20.


 
 
 
 
Partenaires

Hébergement Web