2012-12-20 17 views
0

嗨,我有以下flex代碼,但我不知道如何顯示xml的結果。目前,文本框的結果爲String [],但我需要它來顯示XML的結果作爲100,200,300,400,500感謝如何在Flex中顯示Web服務結果?

<?xml version="1.0" encoding="utf-8"?> 

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      xmlns:hellos="services.hellos.*" 
      minWidth="955" minHeight="600"> 
<fx:Script> 
    <![CDATA[ 
     import mx.events.FlexEvent; 

     protected function 
     form_creationCompleteHandler(event:FlexEvent):void 
     { 
      sayHelloResult.token = hellos.sayHello(); 
     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <hellos:Hellos id="hellos"/> 
    <s:CallResponder id="sayHelloResult"/> 
</fx:Declarations> 
<s:Form id="form" creationComplete="form_creationCompleteHandler(event)"> 
    <s:FormItem label="SayHello"> 
     <s:TextInput text="String[]"/> 
    </s:FormItem> 
</s:Form> 

</s:Application> 

XML是如下:

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance"> 
    <soapenv:Body> 
    <sayHelloResponse xmlns="http://services"> 
    <sayHelloReturn>100</sayHelloReturn> 
    <sayHelloReturn>200</sayHelloReturn> 
    <sayHelloReturn>300</sayHelloReturn> 
    <sayHelloReturn>400</sayHelloReturn> 
    <sayHelloReturn>500</sayHelloReturn> 
    </sayHelloResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

回答

1

添加ID到標籤:

<s:TextInput id="resultText" text=""/> 

添加處理程序導致呼叫響應的事件:

<s:CallResponder id="sayHelloResult" result="processResult()" /> 

應用響應這樣的:

protected function processResult():void{ 
    var r:Array = []; 
    for each(var xml:XML in sayHelloResult.lastResult..*::sayHelloReturn){ 
     r.push(xml.toString()); 
    } 
    resultText.text = r.join(','); 
} 

在處理XML,不要忘了命名空間: http://jodieorourke.com/view.php?id=76&blog=news