7 Replies Latest reply on Jun 4, 2007 5:40 AM by firespade

    Binding very complex XML data in DataGrid

    ryumkin@inbox.ru
      So here is an Xml i retrieve from webservice. And as you can see it uses namespaces and so on... So there ar some <q1:StatusOption> tags in here, and i need their props to be bind in DataGrid with columns OptionValue, Description, State... I've tried many ways but with no success. Please help! And if it's possible without arrays. Thanks.


      <RetrieveAttributeMetadataResponse xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/" xmlns=" http://schemas.microsoft.com/crm/2006/WebServices">
      <RetrieveAttributeMetadataResult xsi:type="q1:StatusAttributeMetadata" xmlns:q1=" http://schemas.microsoft.com/crm/2006/Metadata">
      <q1:Name>statuscode</q1:Name>
      <q1:Type>Status</q1:Type>
      <q1:DisplayName>Status</q1:DisplayName>
      <q1:Description>Reason for the status of the contact.</q1:Description>
      <q1:IsCustomField>false</q1:IsCustomField>
      <q1:RequiredLevel>None</q1:RequiredLevel>
      <q1:DefaultValue xsi:type="xsd:int">-1</q1:DefaultValue>
      <q1:ValidForCreate>true</q1:ValidForCreate>
      <q1:ValidForRead>true</q1:ValidForRead>
      <q1:ValidForUpdate>true</q1:ValidForUpdate>
      <q1:DisplayMask>ValidForAdvancedFind ValidForForm ValidForGrid</q1:DisplayMask>
      <q1:NextValue>3</q1:NextValue>
      <q1:Options>
      <q1:StatusOption>
      <q1:OptionValue>1</q1:OptionValue>
      <q1:Description>Active</q1:Description>
      <q1:State>0</q1:State>
      </q1:StatusOption>
      <q1:StatusOption>
      <q1:OptionValue>2</q1:OptionValue>
      <q1:Description>Not active</q1:Description>
      <q1:State>1</q1:State>
      </q1:StatusOption>
      </q1:Options>
      </RetrieveAttributeMetadataResult>
      </RetrieveAttributeMetadataResponse>
        • 1. Re: Binding very complex XML data in DataGrid
          firespade
          Check this. I looked over your XML and came up with a solution. However, since its your webservice, I lack access so I just used an XML document and included it into an HTTPService via the URL param. Here is the entire code. It outputs it into a three-column datagrid. This is actually the first time I have ever traversed through QName elements. So this is pretty cool.

          Hope it helps!!!

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="dSrv.send();">

          <mx:Script>
          <![CDATA[
          import mx.collections.*;
          import mx.controls.*;
          import mx.rpc.events.*;
          import mx.events.*;

          [Bindable]
          private var records:ArrayCollection = null;
          private function recordsResult(event:ResultEvent):void {
          records = new ArrayCollection();
          records = event.result.RetrieveAttributeMetadataResponse.RetrieveAttributeMetadataResult.Options.St atusOption as ArrayCollection;
          }
          ]]>
          </mx:Script>

          <mx:Panel width="100%" height="100%" layout="horizontal" id="p" title="Test Bed #1">
          <mx:DataGrid width="100%" height="100%" id="dg" dataProvider="{records}">
          <mx:columns>
          <mx:DataGridColumn headerText="OptionValue" dataField="OptionValue"/>
          <mx:DataGridColumn headerText="Description" dataField="Description"/>
          <mx:DataGridColumn headerText="State" dataField="State"/>
          </mx:columns>
          </mx:DataGrid>
          </mx:Panel>

          <mx:HTTPService id="dSrv" url="data/catalog.xml"
          result="recordsResult(event);"
          />

          </mx:Application>
          • 2. Re: Binding very complex XML data in DataGrid
            firespade Level 1
            ======================== UPDATE ==========================

            Apparently you don't want to use array's to use the data, however the only way to traverse the xml correctly is by passing the nested layer that you want into an ArrayCollection object and then using it in place of the service directly. I tried to use an enumeration of the data directly from the HTTPService as a provider (E.g. q1[12]) but Flex 2 doesn't allow you to directly instantiate an xml value like an array value. So I made a bindable method, and it does all the work for you. Sorry for the bad news, but thats what I've figured out so far. Good luck and thanks for the learning experience. :)
            • 3. Re: Binding very complex XML data in DataGrid
              ryumkin@inbox.ru Level 1
              Cool but not enough i guess :)
              DataGrid doesn't filling... event.result is XML but event.result.RetrieveAttributeMetadataResponse is Empty, and as a result the array is null. Here is my code, maube it can helps

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
              <![CDATA[
              import mx.accessibility.AlertAccImpl;
              import mx.collections.*;
              import mx.controls.*;
              import mx.rpc.events.*;
              import mx.events.*;

              [Bindable]
              private var records:ArrayCollection = null;
              private function recordsResult(event:ResultEvent):void
              {
              records = new ArrayCollection();
              records = event.result.RetrieveAttributeMetadataResponse.RetrieveAttributeMetadataResult.Options.St atusOption as ArrayCollection;
              }
              ]]>
              </mx:Script>
              <mx:WebService id="wsMetadataService" wsdl="#####"
              useProxy="false" showBusyCursor="true" result="recordsResult(event);">
              <mx:operation name="RetrieveAttributeMetadata" resultFormat="e4x">
              <mx:request xmlns:q1=" http://schemas.microsoft.com/crm/2006/Metadata">
              <entityName>contact</entityName>
              <attributeName>statuscode</attributeName>
              </mx:request>
              </mx:operation>
              </mx:WebService>
              <mx:Panel x="10" y="10" width="758" height="565" layout="absolute">
              <mx:Button click="wsMetadataService.RetrieveAttributeMetadata.send()" x="10" y="10" label="Request"></mx:Button>
              <mx:DataGrid x="10" y="343" id="dg" width="400" dataProvider="{records}">
              <mx:columns>
              <mx:DataGridColumn headerText="OptionValue" dataField="OptionValue"/>
              <mx:DataGridColumn headerText="Description" dataField="Description"/>
              <mx:DataGridColumn headerText="State" dataField="State"/>
              </mx:columns>
              </mx:DataGrid>
              <mx:TextArea id="ta" x="10" y="40" width="400" height="295" text="{wsMetadataService.RetrieveAttributeMetadata.lastResult}"/>
              </mx:Panel>
              </mx:Application>
              • 4. Re: Binding very complex XML data in DataGrid
                firespade Level 1
                instead of calling the click event with "wsMetadataService.RetrieveAttributeMetadata.send()" use "wsMetadataService.send();" instead.
                • 5. Re: Binding very complex XML data in DataGrid
                  ryumkin@inbox.ru Level 1
                  It says no such method...

                  [RPC Fault faultString="Couldn't find method 'send' in service." faultCode="Client.NoSuchMethod" faultDetail="null"]
                  • 6. Re: Binding very complex XML data in DataGrid
                    ryumkin@inbox.ru Level 1
                    I found an answer on the other forum. Check this out :)

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">
                    <mx:Script>
                    <![CDATA[

                    private var myxml:XML = <RetrieveAttributeMetadataResponse xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/" xmlns=" http://schemas.microsoft.com/crm/2006/WebServices">
                    <RetrieveAttributeMetadataResult xsi:type="q1:StatusAttributeMetadata" xmlns:q1=" http://schemas.microsoft.com/crm/2006/Metadata">
                    <q1:Name>statuscode</q1:Name>
                    <q1:Type>Status</q1:Type>
                    <q1:DisplayName>Status</q1:DisplayName>
                    <q1:Description>Reason for the status of the contact.</q1:Description>
                    <q1:IsCustomField>false</q1:IsCustomField>
                    <q1:RequiredLevel>None</q1:RequiredLevel>
                    <q1:DefaultValue xsi:type="xsd:int">-1</q1:DefaultValue>
                    <q1:ValidForCreate>true</q1:ValidForCreate>
                    <q1:ValidForRead>true</q1:ValidForRead>
                    <q1:ValidForUpdate>true</q1:ValidForUpdate>
                    <q1:DisplayMask>ValidForAdvancedFind ValidForForm ValidForGrid</q1:DisplayMask>
                    <q1:NextValue>3</q1:NextValue>
                    <q1:Options>
                    <q1:StatusOption>
                    <q1:OptionValue>1</q1:OptionValue>
                    <q1:Description>Active</q1:Description>
                    <q1:State>0</q1:State>
                    </q1:StatusOption>
                    <q1:StatusOption>
                    <q1:OptionValue>2</q1:OptionValue>
                    <q1:Description>Not active</q1:Description>
                    <q1:State>1</q1:State>
                    </q1:StatusOption>
                    </q1:Options>
                    </RetrieveAttributeMetadataResult>
                    </RetrieveAttributeMetadataResponse>;



                    private function onCreationComplete():void
                    {
                    var result:XMLList = myxml..*::StatusOption;


                    dg1.dataProvider = result;
                    }

                    private function getAttributeValue(item:Object, column:DataGridColumn):String
                    {
                    var xmlList:XMLList = XML(item).child(new QName(" http://schemas.microsoft.com/crm/2006/Metadata",column.dataField));

                    return xmlList[0].toString();
                    }
                    ]]>
                    </mx:Script>

                    <mx:DataGrid id="dg1" labelFunction="getAttributeValue">
                    <mx:columns>
                    <mx:DataGridColumn dataField="OptionValue"/>
                    <mx:DataGridColumn dataField="Description" />
                    <mx:DataGridColumn dataField="State" />
                    </mx:columns>
                    </mx:DataGrid>
                    </mx:Application>
                    • 7. Binding very complex XML data in DataGrid
                      firespade Level 1
                      Wow alright well thats pretty awesome. You can define what data is classified in a component from the Script. That's pretty handy actually. I'm glad you finally got your answer, I sure learned a lot. Sorry find the final solution, but I made some progress at least haha.