2 Replies Latest reply on Dec 21, 2009 10:50 AM by Francisc

    Reading XML Dynamically + After exporting

    vksvicky

      I have a standalone program written and I read the XML file like

       

      <mx:XML id="dataTiny"

                  source="xml/dataTiny.xml" />

       

      When I export from the builder, even the XML file content gets embedded.

       

      What I need is to read the XML file from a particular location and if the file is not there, show an error.

       

      How can I achieve this?

        • 1. Re: Reading XML Dynamically + After exporting
          vksvicky Level 1

          Also I have a lot of dependency I've created with the id 'dataTiny', how can I assign the data back to that if there is a different mechanism for reading XML?

          • 2. Re: Reading XML Dynamically + After exporting
            Francisc Level 3

            I would use HTTPService. Here's an example of `how-to`:

             

            <mx:Script>

            <![CDATA[

             

            import mx.controls.Alert;

            import mx.rpc.events.FaultEvent;

            import mx.rpc.events.ResultEvent;

            import mx.collections.ArrayCollection;

             

            private var myRetrivedData:ArrayCollection;

             

            private function getXMLData():void

            {

                 httpService.send();

            }

            private function httpFaultHandler(event:FaultEvent):void

            {

                 Alert.show("Cannot load XML file.","Error");

            }

            private function httpResultHandler(event:ResultEvent):void

            {

                 myRetrivedData=event.result.elements.element;

            }

            ]]>

            </mx:Script>

             

            <mx:HTTPService id="httpService" url="someXMLFile.xml"

                 fault="httpFaultHandler(event)" result="httpResultHandler(event)"/>

             

            <mx:DataGrid id="myDataGrid" dataProvider="{myRetrivedData}"/>

             

            Hope this helps.

            To change the source dynamically do this: httpService.url="http://www.mysite.com/xmlFeed.xml" or httpService.url="xmlFeed.xml" from a function.

            1 person found this helpful