5 Replies Latest reply on Jul 17, 2007 6:05 PM by ntsiii

    Load external XML file

    munchkin65
      I am trying to write a test program. I have a program that is going to get it's data from an XML file when it is first loaded. That XML file is going to be a local file that sit's in same folder as the flex program (rather than online or through a url address). Basically, I'm trying to find a way to open or load that file, then parse through it and store the xml data, then close the xml file (rather than using an rss feed). Everything I'm finding is only telling me how to load the data in through a url address. Is there any simple way to open a text or xml file?
        • 1. Re: Load external XML file
          ur_dtrain Level 1
          <mx:HTTPService id="productService" url=myXML.xml"
          result="myResultHandler(event)"/>

          Grabs the local file myXML.xml. You then parse it in the handler function.
          • 2. Re: Load external XML file
            Silver27
            I kinda have a similar question, if you wanted to load and view multiple xml files??? I already have part of my application that has a filereferenceList and it's grabbing all my files, but how would I be able to click on one of those files to load into another datagrid??
            • 3. Load external XML file
              dex002 Level 1
              This loads the external XML file which resides in the same directory as the Flex app. When its completely loaded, it converts the XML to the new standard and outputs it into a text field:

              <?xml version="1.0"?>
              <!-- Simple example to demonstrate the HorizontalList Control. -->
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">

              <mx:Script>
              <![CDATA[
              import mx.controls.Image;
              import flash.display.*;
              import flash.events.IOErrorEvent;
              import flash.net.URLLoader;
              import flash.net.URLRequest;
              import flash.events.Event;
              import flash.events.ProgressEvent;

              public function init():void
              {
              var loader:URLLoader = new URLLoader();
              var request:URLRequest = new URLRequest("catalog.xml");
              loader.load(request);
              loader.addEventListener(Event.COMPLETE, displayData)
              }

              public function displayData ( event:Event ):void {
              var myData:XML = new XML (event.target.data)
              XMLtext.text = myData.toXMLString()
              }

              ]]>
              </mx:Script>
              <mx:Panel title="XML Output" height="592" width="100%"
              paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" layout="absolute">
              <mx:TextArea id="XMLtext" bottom="143" right="238" left="10" top="10"/>
              </mx:Panel>
              </mx:Application>
              • 4. Re: Load external XML file
                xrum

                i'm goign crazzzzy here.


                i have a list, that reads XML.
                i want that list to update on production without me having to build the project all the time, but by just uploading a new XML file.

                i think the function i need is this:
                [code]
                private function LoadMyXML():void
                {
                var myXML:XML = new XML();
                var XML_URL:String = "xml/AO_Other.xml";
                var myXMLURL:URLRequest = new URLRequest(XML_URL);
                var myLoader:URLLoader = new URLLoader(myXMLURL);
                myLoader.addEventListener("complete", xmlLoaded);

                function xmlLoaded(evtObj:Event)
                {
                myXML = XML(myLoader.data);
                trace("Data loaded.");
                }
                }

                [/code]
                my xml looks like this:
                [code]
                <AO_OTHER>
                <category title="Administrative Groups">
                <link title="Administrative Groups" url="sadfsf"/>
                </category>
                <category title="AO Survey Results">
                <link title="AO Survey Results" url="sdfsdf202.pdf"/>
                </category>
                </AO_OTHER>
                [/code]
                and the error i keep getting is htis:

                TypeError: Error #1090: XML parser failure: element is malformed.
                at TabTest/private:LoadMyXML/xmlLoaded()[C:\Flex\SearchTest\TabTest.mxml:25]
                at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at flash.net::URLLoader/flash.net:URLLoader::onComplete()



                :(
                what am i doing wrong?
                am i even going though this the right way?

                thanks!
                • 5. Re: Load external XML file
                  ntsiii Level 3
                  Are you sure you should be looking at myLoader.data and not at the event object?

                  I prefer HTTPRequest over URLLoader.

                  Tracy