3 Replies Latest reply on Jul 27, 2007 1:59 PM by ntsiii

    Displaying complex xml in a Datagrid

    neopium
      Hello everybody,

      I have a problem displaying an XML file containing both attributes and text. I've looked through this forum and Internet and could not find any suitable answer.

      So here is my XML file (sorry, it's in French :-D) :
      <?xml version="1.0" encoding="UTF-8"?>
      <controles xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
      xmlns=" http://www.exemple.org/controle"
      xsi:schemaLocation=" http://www.exemple.org/controle controle.xsd">
      <Indicateur>
      <Nom>indicateur1</Nom>
      <Min>0.0</Min>
      <Max>100.0</Max>
      </Indicateur>
      <Indicateur>
      <Nom>indicateur2</Nom>
      <Min>0.0</Min>
      <Max>100.0</Max>
      </Indicateur>
      </controles>

      I use an HTTPService to retrieve the XML :
      <mx:HTTPService
      id="controle"
      url="xml/myFile.xml"
      result="resultHandler(event)"
      resultFormat="e4x"/>

      And here is my resultHandler function :
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;

      [Bindable]
      private var xmlData:XMLList;

      private function resultHandler(event:ResultEvent):void
      {
      var result:XML = event.result as XML;
      xmlData = result.Indicateur;
      }
      ]]>
      </mx:Script>

      My problem is that xmlData is always null.
      If I change it to :
      xmlData = result.children();
      I can see it contains the whole XML, with the attributes :
      <Indicateur xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns=" http://www.exemple.org/controle">
      <Nom>indicateur1</Nom>
      <Min>0.0</Min>
      <Max>100.0</Max>
      </Indicateur>
      <Indicateur xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns=" http://www.exemple.org/controle">
      <Nom>indicateur2</Nom>
      <Min>0.0</Min>
      <Max>100.0</Max>
      </Indicateur>

      but that is not be displayed by my datagrid :
      <mx:DataGrid
      id="dg"
      dataProvider="{xmlData}">
      <mx:columns>
      <mx:DataGridColumn headerText="Variable" dataField="Nom"/>
      <mx:DataGridColumn headerText="Min" dataField="Min"/>
      <mx:DataGridColumn headerText="Max" dataField="Max"/>
      </mx:columns>
      </mx:DataGrid>

      Any idea would be the most welcome !