2 Replies Latest reply on Nov 1, 2008 10:08 PM by Xilian

    datagrid population with nested xml help

    Xilian
      Hello,
      i'm trying to display data from an xml file to a datagrid. Below are samples of the xml file format and the datagrid code. However, i cannot get the values of the nested tags. Help with this appreciated.

      Thanks
      //====================<XML File>=========================================
      <results>
      <profile>
      <name>myname</name>
      <location>New York City, New York</location>
      <industry>Financial Services and Banking</industry>
      <experience>
      <company id="1">
      <firm>Lehmann Brothers</firm>
      <title id="1">Vice President - Information Technology</title>

      <duration id="1">August 2000 - September 2008</duration>
      <title id="2">Snr Developer</title>

      <duration id="2">May 1998 - August 2000</duration>
      <title id="3">Technology Associate</title>

      <duration id="3">May 1995 - May 1998</duration>
      </company>
      </experience>
      <education>
      <college id ="1"> Carnegie-Mellon </college>
      <college id ="2"> University of California - Berkley</college>
      </education>
      </profile>
      </results>

      //=================<WebService code to retrieve data>===================
      <mx:HTTPService id="searchResultsRetriever" resultFormat="e4x" url="search_results.xml"/>

      //====================<DataGrid population code>=====================
      <mx:DataGrid x="10" y="10" width="1098" height="322" borderColor="#71B7E7"
      alternatingItemColors=[#D6E0E6, #FFFFFF]"
      borderStyle="inset"
      id="profileViewer"
      dataProvider="{searchResultsRetriever.lastResult.profile}"
      horizontalScrollPolicy="auto">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Company" dataField="firm"/>
      <mx:DataGridColumn headerText="Location" dataField="location"/>
      <mx:DataGridColumn headerText="Industry" dataField="industry"/>
      <mx:DataGridColumn headerText="Experience" dataField="title"/>
      <mx:DataGridColumn headerText="Duration" dataField="duration"/>
      <mx:DataGridColumn headerText="Education" dataField="college"/>
      </mx:columns>
      </mx:DataGrid>


        • 1. Re: datagrid population with nested xml help
          m_hartnett Level 3
          The problem with this is that it is not looking down far enough into the XML nodes. The datagrid is looking at the <results> node and only finding one item in it <profile>. All the nodes under profile are what you are trying to display.

          Your solution would be to remove the <results> node and deliver only the nodes from <profile> on down or let your resultHandler pull the children out of the <results> node into an XMLList or XMLListCollection object and make that object the source of the datagrid.

          <results>
          <profile>
          <name>myname</name>
          <location>New York City, New York</location>
          <industry>Financial Services and Banking</industry>
          <experience>
          <company id="1">
          <firm>Lehmann Brothers</firm>
          <title id="1">Vice President - Information Technology</title>

          <duration id="1">August 2000 - September 2008</duration>
          <title id="2">Snr Developer</title>

          <duration id="2">May 1998 - August 2000</duration>
          <title id="3">Technology Associate</title>

          <duration id="3">May 1995 - May 1998</duration>
          </company>
          </experience>
          <education>
          <college id ="1"> Carnegie-Mellon </college>
          <college id ="2"> University of California - Berkley</college>
          </education>
          </profile>
          </results>
          • 2. Re: datagrid population with nested xml help
            Xilian Level 1
            thanks, figured it out a little earlier. Used an item renderer instead.