8 Replies Latest reply on Jun 23, 2009 12:34 PM by Jerry62712

    Flex and XML input (and output too)

    Jerry62712 Level 1

      Starting with this code (how do you enclose code here?):

       

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

       

          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.events.FaultEvent;
                  import mx.controls.Alert;

       

                                 [Bindable]
                                 private var shippingInfo:XMLList;

       

                  public function handleXML(event:ResultEvent):void
                  {
                      shippingInfo = event.result.option as XMLList;
                  }

       

                  public function handleFault(event:FaultEvent):void
                  {
                     Alert.show(event.fault.faultString, "Error");
                  }
              ]]>
          </mx:Script>

       

          <mx:HTTPService result="handleXML(event);" fault="handleFault(event);" id="xmlRPC" resultFormat="e4x"
              url="http://examples.adobe.com/flex3app/flex3samples/exchangingdata/xml/xmlHttpService.jsp" useProxy="false">
              <mx:request xmlns="">
                  <zipcode>{zipcode.text}</zipcode>
                  <pounds>{weight_lb.text}</pounds>
              </mx:request>
          </mx:HTTPService>

       

          <mx:Label x="56" y="32" text="Zip Code" width="55" height="18" textAlign="right" fontWeight="bold"/>
          <mx:Label x="56" y="58" text="Weight" width="55" height="18" textAlign="right" fontWeight="bold"/>
          <mx:TextInput x="130" y="32" id="zipcode" width="160" height="22"/>
          <mx:TextInput x="130" y="58" id="weight_lb" width="160" height="22"/>
          <mx:Button x="130" y="95" label="Get Shipping Options" click="xmlRPC.send();" width="160" height="22"/>
          <mx:DataGrid
              dataProvider="{shippingInfo}"
              x="80" y="141" width="262" height="92" id="shippingOptionsList" editable="false" enabled="true">
              <mx:columns>
                  <mx:DataGridColumn headerText="Service" dataField="service" />
                  <mx:DataGridColumn headerText="Price" dataField="price" />
              </mx:columns>
          </mx:DataGrid>

       

      </mx:Application>

       

      The above is the sample code of getting XML data into a Flex application.  While it looks simple, I'm not sure of how to apply this to my situation.  I want to invoke my Flex application with XML parameters.  It would look like this:

       

      http://10.21.85.50:8080/FSCalc/FSCalcServlet.do?xml=<?xml version="1.0" encoding="UTF-8" ?><FSParm><GrossMonthlyEarnedIncome>2000</GrossMonthlyEarnedIncome><GrossMonthlyOtherInco me>694</GrossMonthlyOtherIncome><HouseholdSize>6</HouseholdSize><QualifyingMember>true</Qu alifyingMember><SimplifiedProcessingUnitInd>true</SimplifiedProcessingUnitInd><DependentCa reCostsAmt>500</DependentCareCostsAmt><NumberOfChildrenUnder2></NumberOfChildrenUnder2><Nu mberOfChildrenOver2>1</NumberOfChildrenOver2><CourtOrderedSupportAmt>300</CourtOrderedSupp ortAmt><MedicalExpenseAmt>250</MedicalExpenseAmt><MonthlyRentOrMortgageAmt>250</MonthlyRen tOrMortgageAmt><MonthlyInsuranceAndTaxAmt>0</MonthlyInsuranceAndTaxAmt><UtilityType>liheap </UtilityType><TotalAssets>2999</TotalAssets></FSParm>

       

      So the URL contains the xml I'm assuming from an HTTPservice.  Any ideas of how to apply the above code to this data/url?

       

      Thanks, Jerry

        • 1. Re: Flex and XML input (and output too)
          leybniz Level 4

          Ideally this url http://10.21.85.50:8080/FSCalc/FSCalcServlet.do

          should respond with the xml body you have listed as GET param named 'xml'.

           

          put your backend script url instead of

          http://examples.adobe.com/flex3app/flex3samples/exchangingdata/xml/xmlHttpService.jsp

           

           

          and you'll be able to get XML from theserver script, if you want to send it back

          use xmlRPC.send(/*put your xml variable here*/);  this line will POST your xml variable to the service url

          • 2. Re: Flex and XML input (and output too)
            Jerry62712 Level 1

            Thanks for your reply.  As you can tell, I'm pretty new at Flex.

             

            The FSCalcServlet.do is a java servlet called in the current java version of the program I'm rewriting in Flex.  I'm not sure if it would be helpful to include it here, but I can if it will shed any light on the subject.  The goal is to accept the xml formatted input, do the calculations and output another xml file that will go back to the program that invoked this one.

             

            The file needs to be parsed so I can tell what (from one to many) parameters will be passed in and set my programs variables to the input values.  That's all I'm going to do to start this - baby steps and all that.  Later I'll worry about the output side.

             

            In the code it looked like Flex will do the parsing automatically.  This:

                                       [Bindable]
                                       private var shippingInfo:XMLList;

                         public function handleXML(event:ResultEvent):void
                        {
                            shippingInfo = event.result.option as XMLList;
                        }

             

            says to me we have a list variable called shippingInfo that accepts XML formatted data.  It is set when handleXML is invoked with the xml data coming from the event.  The following:


                 <mx:DataGrid
                      dataProvider="{shippingInfo}"
                      x="80" y="141" width="262" height="92" id="shippingOptionsList" editable="false" enabled="true">
                     <mx:columns>
                         <mx:DataGridColumn headerText="Service" dataField="service" />
                         <mx:DataGridColumn headerText="Price" dataField="price" />
                     </mx:columns>
                 </mx:DataGrid>

             

            says to me that the variable shippingInfo is automatically (bound) to the data grid object.  Within that, two column exist with names (service, price) that I assume are the same as in the xml input.  Once they are in the grid, they can be used like any local object.  I don't know if I need to put those values into the current ones in the form as it would never actually display anywhere.  The results of the calculations would have to be put into a xml file and sent out (don't know if they store a file or what), but that is for the second phase of the operation.

             

            Does that sound like I'm on the right track?

            • 3. Re: Flex and XML input (and output too)
              leybniz Level 4

              Definitely! Affirmative! keep going

              • 4. Re: Flex and XML input (and output too)
                Jerry62712 Level 1

                I thought I was getting there, then I hit a wall.  Do you know of any other examples?  I've literally spent the last 5 hours trying to find any, but couldn't.  I emailed the partners program using their form (xml) for the question, but haven't heard from them on my contact two weeks ago or the one from two months ago.  That program doesn't seem very responsive.

                • 5. Re: Flex and XML input (and output too)
                  leybniz Level 4

                  Hmm? don't get me wrong, but why have you made a decision to use Flex to re-write/replace server side?

                  actually it's not really clear to me what kind of difficulties are you experiencing? there should be some concrete pitfalls?

                  • 6. Re: Flex and XML input (and output too)
                    Jerry62712 Level 1

                    Flex was chosen by my boss' boss' boss.  You can't fight city hall <g>.

                     

                    The problem I'm having right now is how to access and use a potential XML stream.  One way the application is used is a normal web page.  Other way it is used is invoked with an XML stream to simulate the input and export an XML file.  That entire thing is driven by a telephone application that takes in stuff, calls the webpage and "reads" the results to the person that called their system.

                     

                    We've got the web page part 95% done with one of my programmers finishing the Spanish language conversion.  Another one of them has written the web page shell to use the SWF file and the other person is writing the documentation.  I am both the project leader and doing the .AS and class programming.

                     

                    We are going to replace a java application that runs on a TOMCAT server.  The state (I work for Illinois) is dropping this kind of server.

                     

                    Extensively searching (defined as hours and hours of searching) has failed to produce any examples of Flex and reading URL parameters, especially in XML format.  As a member of the partners program, I have also posted this with their help people, but months has passes since the first one and no contacts have returned an email or call yet.  Without the XML ability, we will just have to keep the TOMCAT server going and hope that in the next year or so that we can proceed with the FLEX conversion.  By then maybe there will be examples of this here or the partners program will respond.

                     

                    Flex won't be on the server side AFAIK.  It runs on the client machine and is put there by a invocation of a web page.  Down the road I want to reach a DB2 database to populate some standards tables, but this is a much more important issue at this time.

                    • 7. Re: Flex and XML input (and output too)
                      leybniz Level 4

                      wow, whole story

                      strange situation, I'm in doubt of what could be helpful here Sorry.

                      • 8. Re: Flex and XML input (and output too)
                        Jerry62712 Level 1

                        I would never have guess something like this would have confounded all the experts here.  And not just here.  I was in a video/web conference with "the top guys" on May 6th.  I posted a question on the partners program on June 17th.  In July I will see if our sales rep can do any good.  In August I'll quit in disgust over having wasted a quarter of a year to get one answer.

                         

                        Please don't confuse my anger with Adobe with any of the great helpers in forums.  I do the same in my fields in those forums I help in.  I don't expect any helper to have all knowledge of everything, nor do I.  That's why we pay big bucks for the partners program which hasn't helped with it at all (so far in 6 weeks of having the problem).