2 Replies Latest reply on Apr 21, 2008 10:57 AM by dan19460

    Data Grid Provider, XML attributes

    the_lastBoyScout
      Hi all,
      I'm trying to populate a dataGrid component with following XML sample:
      <root>
      <row>
      <column name="dataGrid Header 1">Test Data 1.1</column>
      <column name="dataGrid Header 2">Test Data 1.2</column>
      </row>
      <row>
      <column name="dataGrid Header 1">Test Data 2.1</column>
      <column name="dataGrid Header 2">Test Data 2.2</column>
      </row>
      </root>
      ----------------------------------------------------------------
      I assume that it should be something like below, but I can't find a way to make it work:
      ---------------------------------------------------------------
      var dataXML:XMLList = null;
      function resultHandle(event) {
      ....
      dataXML = event.result.root;
      ...
      }
      ----------------------------------------------------------------
      <mx:DataGrid dataProvider="{dataXML.row}">
      <mx:columns>
      <mx:DataGridColumn headerText="column[0].@name" dataField="column.(@name=='dataGrid Header 1')"/>
      <mx:DataGridColumn headerText="column[1].@name" dataField="column.(@name=='dataGrid Header 2')"/>
      </mx:columns>
      </mx:DataGrid>

      -----OR--------

      <mx:DataGrid dataProvider="{dataXML.row}">
      <mx:columns>
      <mx:DataGridColumn headerText="{dataXML.row[0].column[0].@name}" dataField="{column[0]}"/>
      <mx:DataGridColumn headerText="{dataXML.row[0].column[1].@name}" dataField="{column[1]}"/>
      </mx:columns>
      </mx:DataGrid>

      -------------------------------------------------------------
      If anyone has any suggestions/comments, I would much appreciate it.
      Thanks
        • 1. Re: Data Grid Provider, XML attributes
          Miguelitez
          Hi there,

          I am looking for a solution like yours, but it seems that flex does not like much the XML attributes nor xpath syntax.

          As a workaround, I would modify your source XML to be
          <row>
          <column>
          <dataGridHeader1>Test Data 1.1</dataGridHeader1>
          </column>
          <column>
          <dataGridHeader2>Test Data 1.2</dataGridHeader2>
          </column>
          </row>

          This way, you can take the appropriate value by describing
          <mx:DataGridColumn headerText="{dataXML.column.dataGridHeader1}" dataField="{column[0]}"/>
          <mx:DataGridColumn headerText="{dataXML.column.dataGridHeader2}" dataField="{column[1]}"/>

          Hope it helps. Let me know if you find the REAL solution to read attributes and Xpath,

          Best regards,
          Miguel
          • 2. Re: Data Grid Provider, XML attributes
            dan19460 Level 1
            Try re-working your solution to assign the event.result to the XMLList instead of event.result.root. The "root" node is implied. If you assign event.result.row to the XMLList variable you will have a collection of rows.

            xmlData = event.result.row;
            trace(xmlData); // you should see an xml fragment containing just "row" objects.

            Hope this helps.

            Dan