2 Replies Latest reply on Jun 5, 2009 9:16 AM by _Natasha_

    How to access this XML data in a grid?

    Handycam Level 1

      I have done many data grids, but for some reason I am getting stuck on how to display this particular XML data in a grid correctly:

       

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

      <tableData>


      <items type="Kitchen access">

      <item><![CDATA[Direct; less than 3 ft. above grade]]></item>

      <item><![CDATA[Direct; one story above grade]]></item>

      <item><![CDATA[Indirect; less than 3 ft. above grade]]></item>

      <item><![CDATA[Indirect; one story above grade]]></item>

      <item><![CDATA[Indirect; more than one story above grade]]></item>

      </items>


      <items type="Flooring removal">

      <item><![CDATA[Flooring to remain]]></item>

      <item><![CDATA[Remove sheet vinyl or linoleum]]></item>

      <item><![CDATA[Remove tile on mortar bed]]></item>

      <item><![CDATA[Remove wood flooring]]></item>

      <item><![CDATA[Remove any floor installed with tenacious adhesive]]></item>

      </items>


      ...etc...


      </tableData>

       

      I want each "items" to be a row, and then each "item" a column within that row.  Is this possible, or should I reformat the XML?

        • 1. Re: How to access this XML data in a grid?
          Gaurav J Adobe Employee

          Its possible. Let say your xml is in a seperate file, try :

           

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

           

               <mx:DataGrid id="dgId" dataProvider="{tableData.items}" editable="true" height="100" width="100%" />

           

          HTH,

          Gaurav Jain

          Flex SDK Team

          • 2. Re: How to access this XML data in a grid?
            _Natasha_ Level 4

            Hi,

            this way only type attribute will be shown.

             

            You can show your data using labelFunction property of column.

            <mx:Script>

            <![CDATA[

            private function myLabel(item:Object, column:DataGridColumn):String

            {

            var n:Number = Number(column.dataField); // number of child to show

            var s:String = XML(item).item[n].toString(); // value

            return s;

            }

            ]]>

            </mx:Script>

            <mx:XML id="dgData" xmlns="">

            <tableData>

             

            <items type="Kitchen access">

            <item><![CDATA[Direct; less than 3 ft. above grade]]></item>

            <item><![CDATA[Direct; one story above grade]]></item>

            <item><![CDATA[Indirect; less than 3 ft. above grade]]></item>

            <item><![CDATA[Indirect; one story above grade]]></item>

            <item><![CDATA[Indirect; more than one story above grade]]></item>

            </items>

             

            <items type="Flooring removal">

            <item><![CDATA[Flooring to remain]]></item>

            <item><![CDATA[Remove sheet vinyl or linoleum]]></item>

            <item><![CDATA[Remove tile on mortar bed]]></item>

            <item><![CDATA[Remove wood flooring]]></item>

            <item><![CDATA[Remove any floor installed with tenacious adhesive]]></item>

            </items>

            </tableData>

            </mx:XML>

            <mx:DataGrid dataProvider="{dgData.items}">

            <mx:columns>

            <mx:DataGridColumn headerText="Column 1" labelFunction="myLabel" dataField="0">

            </mx:DataGridColumn>

            <mx:DataGridColumn headerText="Column 2" dataField="1" labelFunction="myLabel"/>

            <mx:DataGridColumn headerText="Column 3" dataField="2" labelFunction="myLabel"/>

            </mx:columns>

            </mx:DataGrid>