7 Replies Latest reply on Mar 18, 2010 9:30 PM by 2811821

    how to access the following xml data in Flex

    2811821

      <users>

       

      <user dept id="HR">

       

           <user>

                <fname>mm</fname>

                <email>mm_it@gmail.com</email>

           </user>

       

           <user>

                <fname>sss</fname>

                <email>sss_it@gmail.com</email>

           </user>

       

      </dept>

       

      <user dept id="Finance">

       

           <user>

                <fname>ffff</fname>

                <email>fff_it@gmail.com</email>

           </user>

       

           <user>

                <fname>www</fname>

                <email>www_it@gmail.com</email>

           </user>

       

      </dept>

       

      </users>

       

      using HTTP service through access the data

      this my user.xml file i want to display all the item in flex datagrid using tab navigator function................ each tab navigator contain one data grid for corresponding Dept like HR, sales , Finance

       

      corresponding information will display in data grid

       

      first tab navigatore is

       

      HR ->  data grid field like fname , Email

       

      finance -> fname, E Mail

        • 1. Re: how to access the following xml data in Flex
          AdrianWiecek Level 3

          Hi,

           

          You can try this solution (I assume your XML file name is myXML):

           

          <mx:TabNavigator>
                  <mx:Repeater id="rep"
                      dataProvider="{myXML.dept}">
                      <mx:Canvas label="{rep.currentItem.@id}">
                          <mx:DataGrid dataProvider="{rep.currentItem.user}">
                              <mx:columns>
                                  <mx:DataGridColumn dataField="fname"/>
                                  <mx:DataGridColumn dataField="email"/>
                              </mx:columns>
                          </mx:DataGrid>
                      </mx:Canvas>       
                  </mx:Repeater>

          </mx:TabNavigator>

           

          Regards,

          Adrian

          • 2. Re: how to access the following xml data in Flex
            2811821 Level 1

            great for quick reply

             

            my XML file is data.xml

             

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

             

            private var myUser:XML =
            <users>

             

            <dept id="hr">
                <user>
                    <firstName>murali</firstName>
                    <emailAddress>muralidharan_it@hotmail.com</emailAddress>
                </user>
                <user>
                    <firstName>bharathi</firstName>
                    <emailAddress>bharathi_it@hotmail.com</emailAddress>
                </user>
                <user>
                    <firstName>vasa</firstName>
                    <emailAddress>vasa_it@gmail.com</emailAddress>
                </user>
            </dept>
               
            <dept id = "finance">
                <user>
                    <firstName>mohan</firstName>
                    <emailAddress>mohan_it@hotmail.com</emailAddress>
                </user>
                <user>
                    <firstName>vinoth</firstName>
                    <emailAddress>vinoth_it@hotmail.com</emailAddress>
                </user>
            </dept>

             

            <dept ="sales">
                <user>
                    <firstName>manoj</firstName>
                    <emailAddress>manoj_it@hotmail.com</emailAddress>
                </user>
                <user>
                    <firstName>deepan</firstName>
                    <emailAddress>deepan_it@hotmail.com</emailAddress>
                </user>
            </dept>
               
            </users>

             

             

            codings i used

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="absolute" creationComplete="htp.send()">
               
                <mx:HTTPService id="htp" url="data.xml"
                    result="resulthandler(event)"
                    fault="faulthandler(event)"/>
                   
                    <mx:Script>
                        <![CDATA[
                            import mx.collections.ArrayCollection;
                            import mx.rpc.events.FaultEvent;
                            import mx.rpc.events.ResultEvent;
                           
                            [Bindable] private var userlist:ArrayCollection;
                                           
                            private function resulthandler(event:ResultEvent):void
                            {
                                userlist=(htp.lastResult.user.dept.user);
                            }
                           
                            private function faulthandler(event:FaultEvent):void
                            {
                               
                            }
                           
                        ]]>
                    </mx:Script>
                   
                    <mx:TabNavigator>
                    <mx:Repeater id="rep" dataProvider="{data.dept}"> <!--data.xml is my fle name-->
                        <mx:Canvas label="{rep.currentItem.@id}">
                            <mx:DataGrid dataProvider="{rep.currentItem.user}">
                                <mx:columns>
                                    <mx:DataGridColumn headerText="Name" dataField="fname"/>
                                    <mx:DataGridColumn headerText="E Mail" dataField="email"/>
                                </mx:columns>
                            </mx:DataGrid>
                        </mx:Canvas>      
                    </mx:Repeater>

            </mx:TabNavigator>
            </mx:Application>

             

             

            its not show anything

            • 3. Re: how to access the following xml data in Flex
              AdrianWiecek Level 3

              Hi,

               

              Like I said - your XML file in my sample has to be named"myXML".

              In your sample try the following:

               

              <mx:Script>
                          <![CDATA[
                              import mx.rpc.events.FaultEvent;
                              import mx.rpc.events.ResultEvent;
                             
                              [Bindable] private var userlist:XML;

                              private function resulthandler(event:ResultEvent):void
                               {

                                  userlist = htp.lastResult as XML;

                              }

                              
                              private function faulthandler(event:FaultEvent):void
                              {
                                  
                              }
                             
                          ]]>

              </mx:Script>

               

               

              <mx:HTTPService id="htp" url="data.xml"
                      result="resulthandler(event)"
                      fault="faulthandler(event)"
                      resultFormat="e4x"/>

               

              <mx:TabNavigator>
                      <mx:Repeater id="rep"
                          dataProvider="{userlist.dept}">
                           <mx:Canvas label="{rep.currentItem.@id}">
                              <mx:DataGrid dataProvider="{rep.currentItem.user}">
                                  <mx:columns>
                                      <mx:DataGridColumn dataField="fname"/>
                                      <mx:DataGridColumn dataField="email"/>
                                   </mx:columns>
                              </mx:DataGrid>
                           </mx:Canvas>       
                      </mx:Repeater>

              </mx:TabNavigator>

               

               

              Regards,

              Adrian

               

              Message was edited by: AdrianWiecek

              • 4. Re: how to access the following xml data in Flex
                2811821 Level 1

                Hi..

                 

                this code contain no error but its not show any output in browser

                 

                now i execute your code

                • 5. Re: how to access the following xml data in Flex
                  AdrianWiecek Level 3

                  Try this if you have problems and change it the way you want to:

                   

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

                   

                     
                      <mx:XML id="myXML" format="e4x">
                          <users>
                              <dept id="HR">
                                   <user>
                                        <fname>mm</fname>
                                        <email>mm_it@gmail.com</email>
                                   </user>
                                   <user>
                                        <fname>sss</fname>
                                        <email>sss_it@gmail.com</email>
                                   </user>
                              </dept>
                              <dept id="Finance">
                                   <user>
                                        <fname>ffff</fname>
                                        <email>fff_it@gmail.com</email>
                                   </user>
                                   <user>
                                        <fname>www</fname>
                                        <email>www_it@gmail.com</email>
                                   </user>
                              </dept>
                          </users>
                      </mx:XML>
                     
                      <mx:TabNavigator>
                          <mx:Repeater id="rep"
                              dataProvider="{myXML.dept}">
                              <mx:Canvas label="{rep.currentItem.@id}">
                                  <mx:DataGrid dataProvider="{rep.currentItem.user}">
                                      <mx:columns>
                                          <mx:DataGridColumn dataField="fname"/>
                                          <mx:DataGridColumn dataField="email"/>
                                      </mx:columns>
                                  </mx:DataGrid>
                              </mx:Canvas>       
                          </mx:Repeater>
                      </mx:TabNavigator>
                     
                  </mx:Application>

                   

                   

                  Regards,

                  Adrian

                  • 6. Re: how to access the following xml data in Flex
                    2811821 Level 1

                    your great.....

                     

                    thank you

                     

                    the code working now


                    my requirments load the data from external xml.file

                    ok i will try it

                     

                    thank u very much

                    • 7. Re: one more help i want use filter function
                      2811821 Level 1

                      Hi Adrian,

                       

                      happy to discuss once again

                       

                      i need one more help i want use filter function on datagrid each tab navigator contain one search button

                      i cilck that search button i want display that specific data on grid based on textfield