7 Replies Latest reply on Apr 29, 2009 12:11 AM by Richard_Abbott

    Can't load XML data

    hsfrey

      I'm a clueless newbie just testing some examples from the Flex 3 Bible of David Gassner.

      I'm not using Flex Builder.

       

      I copied, compiled, and ran listing 22.2 on p. 657 "E4XParsing.mxml". I've copied it below for those of you without the book at hand.

       

      It compiled and ran without raising an error, but the file "data/invoices.xml" does not load (using mx:HTTPService). The program just sits there quietly.

      There is indeed a file of that name in the data subfolder.

       

      I don't have a system problem loading data, since when I ran another program (listing 16.5, p.483, DisplayBookCollection.mxml) which specified a data file in the identical way, it loaded and ran fine. That program used mx:Model to get the data instead of mx:HTTPService.

       

      Can anyone suggest what the problem might be?

       

      Here's the listing:

       

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

       

      <!-- E4XParsing.mxml, Listing 22.2, p.657 in Flex 3 Bible -->

       

        <mx:Script>
          <![CDATA[
            import helpers.E4XParsingHelper;
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;
                   
          [Bindable]
          private var acExpressions:ArrayCollection;
            [Bindable]
            private var xInvoices:XML;
           
            private function initApp():void
            {
              invoiceService.send();
              acExpressions = new ArrayCollection(E4XParsingHelper.getExpressionsArray());
              XML.prettyIndent=2;
            }
                   
            private function resultHandler(event:ResultEvent):void
            { xInvoices = event.result as XML;      }
                   
            private function evaluate():void
            {
                var xReturn:Object = E4XParsingHelper.evalE4X(xInvoices, expList.selectedIndex);
                if (xReturn.length() == 0)
                { resultString.text = "No XML nodes were found"; }
                else
                { resultString.text = xReturn.toXMLString(); }
            }
            ]]>
           </mx:Script>

       

          <mx:HTTPService id="invoiceService"
                url="data/invoices.xml" resultFormat="e4x"
                result="resultHandler(event)"/>

       

          <mx:VDividedBox width="50%" height="100%">
            <mx:Panel title="XML being searched:" width="100%" height="100%">
              <mx:TextArea width="100%" height="100%" editable="false" text="{xInvoices.toXMLString()}"/>
            </mx:Panel>

       

            <mx:Panel id="expListPanel" title="Select an E4X expression:"
              width="100%" height="100%" >
              <mx:List id="expList" dataProvider="{acExpressions}"
                width="100%" rowCount="{acExpressions.length}"
                change="evaluate()"/>
            </mx:Panel>
          </mx:VDividedBox>

       

          <mx:Panel title="Result as an XML String" height="100%" width="100%">
            <mx:TextArea width="100%" height="100%" id="resultString"/>
          </mx:Panel>
      </mx:Application>

       

           Thanks for any suggestions!

        • 1. Re: Can't load XML data
          SujitG Level 2

          Hi,

           

          Do you have a debug version of Flash Player installed? Are you getting any errors?

          • 2. Re: Can't load XML data
            Barna Biro Level 3

            Hi,

             

            Did you try to debug the application and see if you are getting any response from the HTTService? Most importantly, check if the received response contains the XML data you are waiting. If nothing is returned then try rechecking the path to your XML file.

             

            With best regards,

            Barna Biro

            • 3. Re: Can't load XML data
              m_hartnett Level 3

              With your HTTPService tag you should define a faultHandler

               

              <mx:HTTPService id="invoiceService"
                        url="data/invoices.xml" resultFormat="e4x"
                        result="resultHandler(event)

                        fault="faultHandler(event)"/>

               

              Sample fault handler will catch any errors from the call and use the alert to display them to you.

               

              private function faultHandler(e:FaultEvent) : void {

               

                   Alert(e.message)

              }

              • 4. Re: Can't load XML data
                Richard_Abbott Level 3

                Hi hsfrey,

                just checking that you are trying to run this in the context of a web server rather than just as a Flex app in the launcher? You need a web context to use this kind of functionality. Do you have Tomcat or similar to run the containing html in? As has been suggested, use of a fault handler may help pick this up.

                Richard

                • 5. Re: Can't load XML data
                  hsfrey Level 1

                  Thanks to all for your responses!

                   

                  Yes, I am trying to run the script just with a browser.

                  I had hoped that, since the 'model' command was able to read xml files, the HTTPService would too.

                   

                  I do have the Tomcat server on my machine, as I was using it to evaluate OpenLaszlo.

                  I tried to run the Flex through it, but I don't know enough to do it properly. It can't find the filenames I give it.

                   

                  So, is it the case that there is NO way to use E4X without using a local or remote server?

                   

                  If so, can someone point me to a tutorial on how to feed Flex scripts through Tomcat?

                   

                  Thanks!

                  • 6. Re: Can't load XML data
                    hsfrey Level 1

                    OK! I got it to run - 2 ways!

                     

                    One was to upload it to my web site and run it from there.

                     

                    The other was using the Tomcat server as configured for OpenLaszlo.

                    I had to copy the Flex folder to C:\Program Files\OpenLaszlo Server 4.2.0\Server\lps-4.2.0,

                    and then, with the server running, address the program through the browser at http://127.0.0.1:8080/lps-4.2.0

                     

                    Maybe that's obvious to you guys, but it looks pretty arcane to me! <g>

                     

                    In the absence of real understanding, it took a lot of trial and error. :-(

                    • 7. Re: Can't load XML data
                      Richard_Abbott Level 3

                      Hi hsfrey,

                      glad you got it to work - your solution was pretty much what I was going to write in except I use Tomcat "straight" and hence the physical path is something like C:\Tomcat_6_0\webapps\ROOT\library, with the actual browser link being http://localhost:8080/library/library_references.html.

                      In passing, the 8080 is the port you have set the web server on in configuration - in general terms the port may be a different number (eg WebLogic defaults to 7001, but in all cases it is configurable). If you are running a single web server you may not need the port at all, but I often have three different ones on the go so as to test in different environments (yes, I know this shouldn't be necessary...) and then the port number is the only thing telling them apart.

                      The original problem you faced arose because HTTPService (and a small number of other calls) assume that you have got an HTTP context within which the method is working, and if you just open the file as file://stuff rather than http://stuff then this is missing. Hope that clarifies things,

                      Richard