2 Replies Latest reply on Mar 30, 2007 12:34 PM by silverrider

    xml and data binding

    silverrider
      Hi, I have managed to setup an httpservice that gets me some xml like so (i have set the resultFormat to e4x)…

      <data>
      <agentID>1</agentID>
      <user>3</user>
      <specialty>1</specialty>
      <agentID>2</agentID>
      <user>2</user>
      <specialty>4</specialty>
      <agentID>3</agentID>
      <user>1</user>
      <specialty>3</specialty>
      </data>

      The data comes from a table in my databse(i am using php/mysql). What i want is a generic procedure that will get any table data in xml (which i have done) and then bind it to a datagrid. I have set up the service like so…

      <mx:HTTPService id="table_data" showBusyCursor="true" method="POST" result="getData(event)"
      url=" http://myserver/myfile.php" useProxy="false" resultFormat="e4x">

      and the within the getData() function i have bound the datagrid like so…

      showArrayResult.dataProvider = table_data.lastResult;

      (showArrayResult being my data grid). However, when binding like above nothing appears in the datagrid. Of course, if i bind like this…

      showArrayResult.dataProvider = table_data.lastResult.agentID

      i get one column of all the agentID nodes. But what i want is a way of binding all the top level nodes (agentID, speciality, user) without knowing what they are. i.e. a generic structure that gets all these top level nodes.
      I have been running around in circles trying to figure out a simple way of doing this and would appreciate any help anyone can give me.
        • 1. Re: xml and data binding
          ntsiii Level 3
          That xml format does not lend itself to easy consumption by a datagrid because there is no explicit "row" structure. If you can reastructue the xml like this:
          <data>
          <row>
          <agentID>1</agentID>
          <user>3</user>
          <specialty>1</specialty>
          </row>
          <row>
          <agentID>2</agentID>
          <user>2</user>
          <specialty>4</specialty>
          </row>
          <row>
          <agentID>3</agentID>
          <user>1</user>
          <specialty>3</specialty>
          </row>
          </data>

          This becomes very easy. If you cannot change the xml, then it is harder, and we will need to pre-process the xml on the client side.

          Tracy
          • 2. Re: xml and data binding
            silverrider Level 1
            thanx tracy - that is exactly what i was trying to get my head around. i have changed the server-side page to produce what u suggested and the generated xml is now…

            <data>
            <row>
            <agentID>1</agentID>
            <user>3</user>
            <specialty>1</specialty>
            </row>
            <row>
            <agentID>2</agentID>
            <user>2</user>
            <specialty>4</specialty>
            </row>
            <row>
            <agentID>3</agentID>
            <user>1</user>
            <specialty>3</specialty>
            </row>
            </data>

            - perfect. But, when i change my code to the following (to access the row nodes)…

            showArrayResult.dataProvider = table_data.lastResult.row;

            …i get nothing. yet when i change it thus…

            showArrayResult.dataProvider = table_data.lastResult.row.agentID;

            …the agentID nodes pop up. Any thoughts as to what is happening?