6 Replies Latest reply on Feb 21, 2011 6:50 AM by Loffen89

    I can't seem to understand how to import several XML files in to Flex

    Loffen89

      I can't seem to understand how to import several XML files in to Flex and connecting them to DataGrids. Does someone have any ideas how to make this happen?

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
         
         
          <s:creationComplete>
              <![CDATA[
              loader.addEventListener(Event.COMPLETE, getData);
              loader.load(new URLRequest("http://www.student.hint.no/~100471/mmt134/images/Reiseregning-Konradi_Kare_2011-01-30.xml"));   

       

           ]]>
          </s:creationComplete>
         
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
              var testData:XML;
                 
                  var loader:URLLoader = new URLLoader();

       

                  public function getData(E:Event):void{
                      testData = new XML(E.currentTarget.data);
                      grid.dataProvider = testData.descendants('TravelSpecificationVO');
                  }        
                 
              ]]>
          </fx:Script>
         
         
          <mx:TabNavigator x="22.7" y="39.35" width="536" height="312">
              <s:NavigatorContent label="Tab 1" width="100%" height="100%">
                  <mx:DataGrid x="1.3" y="-2.35" width="507" height="269" id="grid">
                       <mx:columns>
                       <mx:DataGridColumn dataField="to_destinasion" headerText="Til destinasjon"/>
                       <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
                       <mx:DataGridColumn dataField="from_destinasion" headerText="Fra destinasjon"/>
                       <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
                       </mx:columns>
                  </mx:DataGrid>
              </s:NavigatorContent>
              <s:NavigatorContent label="hkuhk" width="100%" height="100%">
              </s:NavigatorContent>
          </mx:TabNavigator>
      </s:Application>

        • 1. Re: I can't seem to understand how to import several XML files in to Flex
          Pablo Souza Level 3

          Hope it helps you:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx">
           <fx:Declarations>
            <fx:XML id="myXML" 
                              source="http://www.student.hint.no/~100471/mmt134/images/Reiseregning-Konradi_Kare_2011-01-30.xml" />
           </fx:Declarations>
           
           <mx:DataGrid dataProvider="{myXML.descendants('TravelSpecificationVO')}">
            <mx:columns>
             <mx:DataGridColumn dataField="to_destination" headerText="Til destinasjon"/>
             <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
             <mx:DataGridColumn dataField="from_destination" headerText="Fra destinasjon"/>
             <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
            </mx:colums>
           </mx:DataGrid>
           
          </s:Application>

           

           

          Let me know if you need additional information.

           

           

           

          Best regards,

          Pablo Souza

          • 2. Re: I can't seem to understand how to import several XML files in to Flex
            UbuntuPenguin Level 4

            When you are declaring a variable and you get to the class type.  Stop halfway, and hit ctrl+spacebar.  A list showing classes that match what you have type will popup, then you select the class you want, and FlexBuilder with add the import statement automagically.

             

            Never mind.


            • 4. Re: I can't seem to understand how to import several XML files in to Flex
              Loffen89 Level 1

              ty for the help, it was very helpful =)

              • 6. Re: I can't seem to understand how to import several XML files in to Flex
                Loffen89 Level 1

                This code is static,  how do i do this over to dynamical.

                The thing is that i must be able to open several loke alike dokuments so it makes no deference what the user writes on the internett page of my,

                here is my code is it is now:

                 

                 

                <?xml version="1.0" encoding="utf-8"?>
                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                               xmlns:s="library://ns.adobe.com/flex/spark"
                               xmlns:mx="library://ns.adobe.com/flex/mx">
                    <fx:Declarations>
                        <fx:XML id="myXML"
                                source="http://www.student.hint.no/~100471/mmt134/images/Reiseregning-Konradi_Kare_2011-01-30.xml" />
                        <fx:XML id="yourXML"
                                source="http://www.student.hint.no/~100471/mmt134/images/Reiseregning-Konradi_Kare_2011-02-01.xml" />
                        <fx:XML id="howXML"
                                source="http://www.student.hint.no/~100455/Reiseregning-Toff_Tor_2011-02-01.xml" />
                        <fx:XML id="thisXML"
                                source="http://www.student.hint.no/~100455/Reiseregning-Thorson_Thor_2011-02-03.xml" />
                    </fx:Declarations>
                   
                    <mx:TabNavigator x="72" y="34" width="539" height="288">
                        <s:NavigatorContent label="Tab 1" width="100%" height="100%">
                            <mx:DataGrid dataProvider="{myXML.descendants('TravelSpecificationVO')}" x="3" y="0" width="524" height="245">
                                <mx:columns>
                                    <mx:DataGridColumn dataField="to_destination" headerText="Til destinasjon"/>
                                    <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
                                    <mx:DataGridColumn dataField="from_destination" headerText="Fra destinasjon"/>
                                    <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
                                </mx:columns>
                            </mx:DataGrid>
                        </s:NavigatorContent>
                        <s:NavigatorContent label="Tab 2" width="100%" height="100%">
                            <mx:DataGrid dataProvider="{yourXML.descendants('TravelSpecificationVO')}" x="3" y="0" width="524" height="245">
                                <mx:columns>
                                    <mx:DataGridColumn dataField="to_destination" headerText="Til destinasjon"/>
                                    <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
                                    <mx:DataGridColumn dataField="from_destination" headerText="Fra destinasjon"/>
                                    <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
                                </mx:columns>
                            </mx:DataGrid>
                        </s:NavigatorContent>
                        <s:NavigatorContent label="Tab 3" width="100%" height="100%">
                            <mx:DataGrid dataProvider="{howXML.descendants('TravelSpecificationVO')}" x="3" y="0" width="524" height="245">
                                <mx:columns>
                                    <mx:DataGridColumn dataField="to_destination" headerText="Til destinasjon"/>
                                    <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
                                    <mx:DataGridColumn dataField="from_destination" headerText="Fra destinasjon"/>
                                    <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
                                </mx:columns>
                            </mx:DataGrid>
                        </s:NavigatorContent>
                        <s:NavigatorContent label="Tab 4" width="100%" height="100%">
                            <mx:DataGrid dataProvider="{thisXML.descendants('TravelSpecificationVO')}" x="3" y="0" width="524" height="245">
                                <mx:columns>
                                    <mx:DataGridColumn dataField="to_destination" headerText="Til destinasjon"/>
                                    <mx:DataGridColumn dataField="from_date" headerText="Klokkeslett"/>
                                    <mx:DataGridColumn dataField="from_destination" headerText="Fra destinasjon"/>
                                    <mx:DataGridColumn dataField="to_date" headerText="Klokkeslett"/>
                                </mx:columns>
                            </mx:DataGrid>
                        </s:NavigatorContent>
                    </mx:TabNavigator>
                   
                </s:Application>