<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Third-Road.net &#187; Flex</title>
	<atom:link href="http://journal.third-road.net/category/developpement/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://journal.third-road.net</link>
	<description>Le journal</description>
	<lastBuildDate>Sun, 22 May 2011 15:12:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[Flex] Récupérer et afficher des données XML</title>
		<link>http://journal.third-road.net/2007/06/08/flex-recuperer-et-afficher-des-donnees-xml/</link>
		<comments>http://journal.third-road.net/2007/06/08/flex-recuperer-et-afficher-des-donnees-xml/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 21:19:49 +0000</pubDate>
		<dc:creator>Mathieu Cabaret</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://journal.third-road.net/2007/06/07/flex-recuperer-et-afficher-des-donnees-xml/</guid>
		<description><![CDATA[Un petit exemple de comment récupérer des données au format XML et les afficher dans un DataGrid en utilisant simplement l&#8217;objet HTTPService.

Pour commencer, on va utiliser le fichier XML suivant, accessible arbitrairement via l&#8217;adresse http://www.mondomaine.tld/monfichier.xml :

&#60;?xml  [...]]]></description>
			<content:encoded><![CDATA[<p>Un petit exemple de comment récupérer des données au format XML et les afficher dans un DataGrid en utilisant simplement l&#8217;objet HTTPService.</p>
<p><span id="more-10"></span></p>
<p>Pour commencer, on va utiliser le fichier XML suivant, accessible arbitrairement via l&#8217;adresse <i>http://www.mondomaine.tld/monfichier.xml</i> :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;donnees<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Babble]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prenom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Michael]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prenom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ville<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Nantes]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ville<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Smith]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prenom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[John]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prenom<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ville<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[New York]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ville<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/clients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/donnees<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ensuite, on va créer le fichier MXML <i>monApplication.mxml</i>  dans lequel on aura créé un objet HTTPService et un DataGrid :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HTTPService</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;maRequete&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://www.mondomaine.tld/monfichier.xml&quot;</span> <span style="color: #000066;">showBusyCursor</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Panel</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;25&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Rafraichir&quot;</span> <span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGrid</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;productGrid&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Nom&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;col1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Prénom&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;col2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Ville&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;col3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:DataGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>On va maintenant associer les données qui seront recueillies par notre service <code>maRequete</code>. Pour cela, on va ajouter l&#8217;attribut <code>dataProvider </code>à cet élément et mettre comme valeur <code>{maRequete.lastResult.clients.client}</code> :</p>
<ul>
<li><code>maRequete</code> : nom de l&#8217;objet HTTPService</li>
<li><code>lastResult</code> : le résultat de la dernière requête</li>
<li><code>clients</code> : le noeud XML qui contient les différents enregistrements que nous voulons afficher</li>
<li><code>client</code> : le noeud XML qui correspond à chaque enregistrement</li>
</ul>
<p>Puis nous associons chaque élément des noeuds <code>clients</code> du fichier XML à chaque colonne du DataGrid (<code>nom</code>, <code>prenom</code> et <code>ville</code>), orthographiés identiquement aux éléments du fichier XML.</p>
<p>Enfin, nous demandons la requête du service, par exemple au lancement de l&#8217;application et lorsque l&#8217;on clique sur le bouton rafraichir en associant aux évènements correspondants la valeur <code>maRequete.send();</code>.</p>
<p>Le fichier <i>monApplication.mxml</i> ressemblera donc à :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;maRequete.send()&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HTTPService</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;maRequete&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://www.mondomaine.tld/monfichier.xml&quot;</span> <span style="color: #000066;">showBusyCursor</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Panel</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;25&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Rafraichir&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;maRequete.send();&quot;</span>  <span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGrid</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;productGrid&quot;</span> <span style="color: #000066;">dataProvider</span>=<span style="color: #ff0000;">&quot;{maRequete.lastResult.clients.client}&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Nom&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;nom&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Prénom&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;prenom&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Ville&quot;</span> <span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;ville&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:DataGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://journal.third-road.net/2007/06/08/flex-recuperer-et-afficher-des-donnees-xml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

