4 Replies Latest reply on Aug 29, 2007 9:46 AM by kcell

    Receiving a XMl file from webservice

    kittuokkade
      hai, iam new to flex applications.
      my requirement is to invoke a webservice from flex client .that is ok.the web service returns Xml Object. how to receive and display that content in flash client.can we do this.

        • 1. Re: Receiving a XMl file from webservice
          paulchabot
          I am also trying to access xml info retreived from my script.
          http://paulchabot.ca/temp/results.xml is what this generates http://paulchabot.ca/temp/test.php
          This is my script data to get the xml
          quote:


          <mx:Script>
          <![CDATA[
          [Bindable]
          var myXML:XML = new XML();
          var XML_URL:String = " http://paulchabot.ca/temp/test.php";
          var myXMLURL:URLRequest = new URLRequest(XML_URL);
          var myLoader:URLLoader = new URLLoader(myXMLURL);

          function initApp():void{
          myLoader.addEventListener("complete", xmlLoaded);
          }

          function xmlLoaded(evtObj:Event):void
          {
          myXML = XML(myLoader.data);

          }
          ]]>
          </mx:Script>



          this loads my xml into myXML, but I cant seem to reference any of the properties, just display the entire text.
          • 2. Receiving a XMl file from webservice
            kcell Level 2
            the xml can be shown when you use textarea (see code ), but I guess you like to display the data in a more user friendly form or ? ;)

            best regards,
            kcell

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

            <mx:Script>
            <![CDATA[
            [Bindable]
            public var myXML:XML = new XML();
            public var XML_URL:String = " http://paulchabot.ca/temp/test.php";
            public var myXMLURL:URLRequest = new URLRequest(XML_URL);
            public var myLoader:URLLoader = new URLLoader(myXMLURL);

            public function initApp():void{
            myLoader.addEventListener("complete", xmlLoaded);
            }

            public function xmlLoaded(evtObj:Event):void
            {
            myXML = XML(myLoader.data);
            textCompleteXML.text = myXML;
            textFirstNode.text = myXML.child(1);
            }
            ]]>
            </mx:Script>
            <mx:TextArea x="0" y="45" width="408" height="301" id="textCompleteXML"/>
            <mx:TextArea x="0" y="372" id="textFirstNode" width="408" height="217"/>


            </mx:Application>
            • 3. Re: Receiving a XMl file from webservice
              kittuokkade Level 1
              yah thanx for reply.but the problem is iam not pointing to any URL of xml document.webservice returns Document .that has to be handled in flex.i hope u got me right.
              • 4. Receiving a XMl file from webservice
                kcell Level 2
                Hi kittuokkade,

                the difference is not that much cause the returned data is in both cases XML.

                Here is an Hello World example of calling a webservice:

                best regards,
                kcell

                <?xml version="1.0"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" buttonMode="true">
                <mx:Script>
                <![CDATA[
                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;


                import mx.controls.Alert;
                private function errorHandling():void
                {
                Alert.show("error");
                }

                private function resultHandling():void
                {
                myWS.HelloWorld.addEventListener("result", serverlistLoaded);
                myWS.HelloWorld.addEventListener("fault" ,errorHandling);
                myWS.HelloWorld();
                }

                private function serverlistLoaded(event:ResultEvent):void
                {
                // result contains the result from the webservice call
                // it it returns xml define what you like to do with it
                Alert.show(event.result.toString());
                }


                ]]>
                </mx:Script>

                <mx:TraceTarget>
                </mx:TraceTarget>

                <mx:WebService id="myWS" wsdl=" http://mycomputer/Service1.asmx?WSDL"
                showBusyCursor="true"
                concurrency="single"
                load="resultHandling()"
                result="resultHandling()"
                fault="errorHandling()">
                </mx:WebService>

                </mx:Application>