3 Replies Latest reply on Sep 27, 2006 9:02 AM by mystrymaster

    Binding a xml document to a datagrid

    mystrymaster
      Should be fairly simpl I would think but I can't get it to work

      here is the xml document

      <?xml version="1.0" encoding="utf-8" ?>

      <booth>
      <station stationID="1">
      <name>Joes Service Center</name>
      <num>9513</num>
      <trucks>10</trucks>
      </station>
      <station stationId ="2">
      <name>Raymonds Auto Body</name>
      <num>9531</num>
      <trucks>2</trucks>
      </station>
      <station stationId ="3">
      <name>Express Automotive</name>
      <num>9520</num>
      <trucks>12</trucks>
      </station>
      </booth>


      Here is the

      mxml document

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      horizontalAlign="center" verticalAlign="middle"
      width="100%" height="100%"
      >
      <mx:XML source="stations.xml" id="stations"/>

      <mx:Panel
      paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
      title="Sample Notepad"
      >
      <mx:DataGrid id="myGrid" dataProvider="{stations}" variableRowHeight="true">
      <mx:columns>
      <mx:DataGridColumn dataField="name"/>
      <mx:DataGridColumn dataField="num"/>
      <mx:DataGridColumn dataField="trucks"/>
      </mx:columns>
      </mx:DataGrid>


      </mx:Panel>
      </mx:Application>
        • 1. Re: Binding a xml document to a datagrid
          mac_martine Level 1
          You need it to be an XML list, so you could do it like this:

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" horizontalAlign="center" verticalAlign="middle"
          creationComplete="init()"
          width="100%" height="100%">

          <mx:XML id="stations" source="stations.xml"/>

          <mx:Script>
          <![CDATA[
          public function init():void
          {
          var myXML:XMLList = new XMLList(stations.station);
          myGrid.dataProvider = myXML;
          }
          ]]>
          </mx:Script>

          <mx:DataGrid id="myGrid" variableRowHeight="true">
          <mx:columns>
          <mx:DataGridColumn dataField="name"/>
          <mx:DataGridColumn dataField="num"/>
          <mx:DataGridColumn dataField="trucks"/>
          </mx:columns>
          </mx:DataGrid>

          </mx:Application>
          • 2. Re: Binding a xml document to a datagrid
            chris.huston.t10 Level 3
            Try changing your DataGrid dataProvider to: {stations.station}
            When I made this change, your data was displayed in the grid.

            Vygo
            • 3. Re: Binding a xml document to a datagrid
              mystrymaster Level 1
              alright that seemed to work perfectly now I am a little lost in going the next step here.

              I have changed the above stations.xml to this

              <facilities>
              <booth boothId ="1">
              <station stationID="1">
              <name>Joes Service Center</name>
              <num>9513</num>
              <trucks>10</trucks>
              </station>
              <station stationId ="2">
              <name>Raymonds Auto Body</name>
              <num>9531</num>
              <trucks>2</trucks>
              </station>
              <station stationId ="3">
              <name>Express Automotive</name>
              <num>9520</num>
              <trucks>12</trucks>
              </station>
              </booth>
              <booth boothId ="2">
              <station stationID="4">
              <name>LakeSide Shell</name>
              <num>9112</num>
              <trucks>6</trucks>
              </station>
              <station stationId ="5">
              <name>G and E Auto Body</name>
              <num>9121</num>
              <trucks>5</trucks>
              </station>
              <station stationId ="6">
              <name>Hawks Service Center</name>
              <num>9122</num>
              <trucks>8</trucks>
              </station>
              </booth>
              </facilities>

              how would I pull just the station the are under the booth with a boothID of 1 or 2?